0
您好,我正在寻找一些帮助,如何将行添加到现有的LINQ对象。在下面的控制器方法中,我有两个结果集,我正在循环网站,并且希望将记录添加到Sites对象中每个记录的“结果”对象。添加记录到一个LINQ对象(concat)从另一个值取得值
我试过CONCAT等,但没有得到任何地方,刚需的小例子来协助,提前千恩万谢,J
public IQueryable<UsersToSite> FindAllUsersToSites(int userId,SystemType obj)
{
var results = (from usersToSite in this._db.UsersToSites
where usersToSite.UserId == userId &&
usersToSite.SystemTypeId == obj
orderby usersToSite.Site.SiteDescription
select usersToSite);
// Now for each remaining Site append a record thats not physically in the database. From the view the user will be able to click these records to ADD new
// I'll then build in a search
var sites = (from site in this._db.Sites
where !(from o in _db.UsersToSites where (o.UserId == userId && o.SystemTypeId == obj) select o.SiteId).Contains(site.SiteId)
orderby site.SiteDescription
select site);
foreach (var site in sites)
{
// HERE I want to create the new ROW in results object
//results = new[results] { new { UsersToSiteId = null, AccessTypeId = null } }.Concat(sites);
//SiteId=site.SiteId,
//UsersToSiteId = 0,
//AccessTypeId = 0,
//UserId = userId
}
return results;
}
这似乎是工作,但现在的结果对象是TOLIST,我试图返回一个IQueryable对象。你知道我怎么可以将列表对象的结果转换回ADD –
John
2011-05-21 09:13:28
@John - 你可以做'return sites.AsQueryable()',但如果你真的想这样做,你需要检查你的代码。 – 2011-05-21 09:15:28