EDN Admin
Well-known member
Hello, I have a nested linq query that is used to populate a treeview. The first select (Title Field) when being bound to the treeview is showing all of the Titles correctly, but if there is multiple occurences I want it to show up once. How can I solve this?
I tried}).Distinct().OrderBy(c => c.LineNumber)
}).Distinct();<-- tried this as well
here is the full Queryvar results =
(from d in mContext.Docs
orderby d.Title ascending
join b in mContext.Base on d.DocId equals b.DocId
join h in mContext.ViewDocItems on b.BaseId equals h.BaseId
where h.ItemId == mGuid
select new
{
Id = d.DocId,
Title = d.Title,
ClassId = d.ClassId,
BaseHis =
(from c in d.Base
select new BaseHistory()
{
BaseId = c.BaseId,
Name = c.Title,
BaseFinal = c.Final.Value,
LineNumber = c.LineNumber.Value
ItemId = h.ItemId
}).Distinct().OrderBy(c => c.LineNumber)
});
foreach(var r in results)
{
var hist = new DocHistory()
{
Id = r.Id,
Title = r.Title,
ClassId = r.ClassId;
};
foreach(var h in r.BaseHis)
{
hist.BaseHis.Add(h);
}
mHistory.Add(hist);
}
View the full article
I tried}).Distinct().OrderBy(c => c.LineNumber)
}).Distinct();<-- tried this as well
here is the full Queryvar results =
(from d in mContext.Docs
orderby d.Title ascending
join b in mContext.Base on d.DocId equals b.DocId
join h in mContext.ViewDocItems on b.BaseId equals h.BaseId
where h.ItemId == mGuid
select new
{
Id = d.DocId,
Title = d.Title,
ClassId = d.ClassId,
BaseHis =
(from c in d.Base
select new BaseHistory()
{
BaseId = c.BaseId,
Name = c.Title,
BaseFinal = c.Final.Value,
LineNumber = c.LineNumber.Value
ItemId = h.ItemId
}).Distinct().OrderBy(c => c.LineNumber)
});
foreach(var r in results)
{
var hist = new DocHistory()
{
Id = r.Id,
Title = r.Title,
ClassId = r.ClassId;
};
foreach(var h in r.BaseHis)
{
hist.BaseHis.Add(h);
}
mHistory.Add(hist);
}
View the full article