Note that there are some explanatory texts on larger screens.

plurals
  1. POPagedList in MVC3 with IQueryable
    primarykey
    data
    text
    <p>I can't understand what i'm doing wrong. Every time I'm getting this error: </p> <p>The entity or complex type 'BusinessLogic.CompanyWithDivisionCount' cannot be constructed in a LINQ to Entities query.</p> <p>I need to get info from 'Company' table and divisions count of each company from 'Division' table, and then make PagedList. Here is my 'Company' table:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using BusinessLogic.Services; using BusinessLogic.Models.ValidationAttributes; namespace BusinessLogic.Models { public class Company { public Company() { Country = "US"; Status = true; } public int Id { get; set; } [Required] [UniqueCompanyName] public string Name { get; set; } public string Street { get; set; } public string City { get; set; } public string State { get; set; } public int Zip { get; set; } public string Country { get; set; } public string ContactInfo { get; set; } [Required] public DateTime EffectiveDate { get; set; } public DateTime TerminationDate { get; set; } public bool Status { get; set; } [Required] public string URL { get; set; } public string EAP { get; set; } public string EAPCredentials { get; set; } public string BrandingColors { get; set; } public string Comments { get; set; } } } </code></pre> <p>Here is my domain model:</p> <pre><code>public class Company { public Company() { Country = "US"; Status = true; } public int Id { get; set; } [Required] [UniqueCompanyName] public string Name { get; set; } public string Street { get; set; } public string City { get; set; } public string State { get; set; } public int Zip { get; set; } public string Country { get; set; } public string ContactInfo { get; set; } [Required] public DateTime EffectiveDate { get; set; } public DateTime TerminationDate { get; set; } public bool Status { get; set; } [Required] public string URL { get; set; } public string EAP { get; set; } public string EAPCredentials { get; set; } public string BrandingColors { get; set; } public string Comments { get; set; } } public class CompanyWithDivisionCount: Company // I'm using this { public int DivisionCount { get; set; } } </code></pre> <p>Here is my controller: </p> <pre><code>public ActionResult CompaniesList(int? page) { var pageNumber = page ?? 1; var companies = companyService.GetCompaniesWithDivisionsCount2(); var model = companies.ToPagedList(pageNumber, PageSize); return View(model); } </code></pre> <p>And here is my service part:</p> <pre><code>public IQueryable&lt;CompanyWithDivisionCount&gt; GetCompaniesWithDivisionsCount2() { return (from c in dataContext.Companies.AsQueryable() select new CompanyWithDivisionCount { Id = c.Id, Name = c.Name, Status = c.Status, EffectiveDate = c.EffectiveDate, URL = c.URL, EAP = c.EAP, EAPCredentials = c.EAPCredentials, Comments = c.Comments, DivisionCount = (int)dataContext.Divisions.Where(b =&gt; b.CompanyName == c.Name).Count() }); } </code></pre> <p>}</p> <p>Thanks for help!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload