In Linq2Sql, it was possible to do a query such as:
using (var db = GetDataContent())
{
var query = from p in db.Brands
where p.Deleted == false
select new BrandImageSummary
{
BrandID = p.BrandID,
BrandUrl = p.BrandUrl,
Description = p.Description,
MetaDescription = p.MetaDescription,
MetaKeywords = p.MetaKeywords,
MetaTitle = p.MetaTitle,
BrandImageUrl = (from p2 in db.SiteImages where p2.FileTypeID == 5 && p2.ForeignID == p.BrandID && p2.Deleted == false orderby p2.Rank select p2.Filename).FirstOrDefault(),
Deleted = p.Deleted,
SupplierCode = p.SupplierCode,
Title = p.Title,
Website = p.Website
};
return query.ToList();
}
With BrandImageUrl being a nested select. Howerver in entity framework, I seem to get the error:
Unable to create a constant value of type 'SiteImage'. Only primitive types or enumeration types are supported in this context.
Is there a way to do this in entity framework?
The idea of the query is to get one brand image, if I was to join, and there was multiple images, I would get multiple rows and I do not want this.
I am using Entity Framework 5.
Thanks for your help