I am currently trying to do a nested query in linq, but I am receiving an error message:
var subcatquery = from categories in mydb.Categories
where categories.ParentId == null
select new
{
category = categories.Name,
subcat = (from sub in mydb.Categories
where sub.ParentId == sub.Id
select new
{
subcatItem = sub.Name,
subcatId = sub.Id
})
};
Results View =The type '<>f__AnonymousType0<subcatItem,subcatId>' exists in both 'myapplication.dll' and 'System.Web.dll'
I can't underestand why.. if I remove the sub query and put it on it's own... it's perfectly fine.
the subcat
type is a collection<>
, is this where the problem is?
class categoryGroup
{
public string category;
public Collection<subcategoryGroup> subcat;
}
class subcategoryGroup
{
public string subcatItem;
public int subcatId;
}
In my project i am using sub query like this it's below
var data = (from con in dbData.tblPresenters
where con.PresenterID == ID
select new
{
Name = con.Name,
Title = dbData.tblTitles.Where(x => x.TitleID == con.PresenterTitleID).FirstOrDefault()
}).ToList();
i think this will help you ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With