【发布时间】:2010-12-14 17:10:02
【问题描述】:
我写了以下代码:
//get the user from the DB
var tmpuser = _db.aspnet_Users.First(q => q.UserName == user.Identity.Name);
//list the direct connections to Verbond
List<Verbond> verb1 = tmpuser.UsersVerbondens
.Where(q => q.Schooljaar.Sch_Schooljaar == schooljaarparam)
.Select(q => q.Verbond)
.ToList();
//list the connected Facturatieverbonden
List<FacturatieVerbonden> verb2 = tmpuser.UsersFacturatieVerbondens
.Where(q => q.Schooljaar.Sch_Schooljaar == schooljaarparam)
.Select(q => q.FacturatieVerbonden)
.ToList();
//loop through the facturatieverbonden and add their verbonds to the first list
foreach (FacturatieVerbonden v in verb2) {
verb1.AddRange(v.Verbonds);
}
//make a distinct list
List<Verbond> test = verb1.Distinct().ToList();
所以,用户可以连接到0个或多个facturatieverbonden,也可以连接到verbond。
facturatieverbonden 下可以有一个或多个verbond。
我需要的是用户通过facturatieverbonden 直接或间接连接到的所有verbond 的列表。
我的代码有效,但我认为它不是很有效。有什么让它更干净的提示吗?
【问题讨论】:
标签: c# linq linq-to-sql lambda