Invalid cast from 'System.Int32' to model.company

710 Views Asked by At

I am trying to make an anonymous object to fetch the data and pass it to view for display. To avoid parsing the data on view level I am trying to get all the information in that anonymous object. Here is my code:

var list = new DataBaseRepository<CrashPlan>().FindAll(x => x.Company.State == "active").Select
                (crashObject => new
                {
                    Company = crashObject.Company,
                    Users = crashObject.Users.Count
                });

            PropertyBag["items"] = list.ToList().OrderBy(x => x.Company.CompanyName);

But when I execute this code I get this error:

Inner exception:
InvalidCastException

Message:
Invalid cast from 'System.Int32' to 'Dicom.Dinet.Core.Models.Company'.

And I have no idea what to fix in the code so that error can be fix.

0

There are 0 best solutions below