TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aleena Saviour
NA
519
87.7k
select subcategory list inside category list
Jul 18 2018 12:52 AM
this is my query for selecting categories and subcategories.
List<Category> lstcat = new List<Category>();
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<SubCat> 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?
Reply
Answers (
2
)
inline arthemetic operation in linq
LINQ to Entities only supports casting EDM primitive or enum