我有一个嵌套查询,linq
用于sql
填充treeview
. Title
绑定到时的第一个选择(字段)正确treeview
显示所有内容Titles
,但如果出现多次,我希望它显示一次。我该如何解决这个问题?
我试过了
}).Distinct().OrderBy(c => c.LineNumber)
}).Distinct();
完整查询
var 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);
}