this is my query for selecting categories and subcategories.
List lstcat = new List();
var categ = _db.Category
.Select(c => new Category()
{
PKCatId = c.PKCatId,
CatName = c.CatName,
Icon = c.Icon,
ActiveIcon = c.ActiveIcon,
Subcat = GetChildren(_db, c.PKCatId)
})
.ToList();
public static List GetChildren(HomeDBContext _db, int parentId)
{
return
_db.subCat.Where(c => c.PKCatId == parentId)
.Select(c => new SubCat
{
PKSubCatId = c.PKSubCatId,
SubCatName = c.SubCatName,
PKCatId = c.PKCatId
})
.ToList();
}
It gives error like "The entity or complex type 'EcomHomeFurniture.Models.Category' cannot be constructed in a LINQ to Entities query."
can anyone help me to solve this?
Ruchi SharavatPosted Jul 18, 2018, 5:28 AM
Karthik ChintalaPosted Jul 19, 2018, 2:04 AM