1
我有以下LINQ查詢:選擇對象,然後修改場LINQ
var list = (from user in serviceu.Repository.FindFind(<<filtering nonsense>>)
from profile in serviceP.Repository.GetQuery().Where(p => p.userID == user.userID).DefaultIfEmpty()
select user).ToList();
基本上我要簡檔添加到我的用戶實體。做這個連接只允許我選擇用戶元素,但是我想改變user.profileID=profile.profileID
的值(我已經擴展了該對象,所以它具有該字段)。這怎麼能以最快的方式完成呢? 我已經解決了它暫時這樣做:
var list = (from user in serviceu.Repository.Find(<<filtering nonsense>>)
from profile in serviceP.Repository.GetQuery().Where(p => p.userID == user.userID).DefaultIfEmpty()
select new { user, profile.ProfileID }).ToList();
list.ForEach(el =>
{
el.user.ProfileID = el.ProfileID.ToString();
});
return list.Select(x => x.user).ToList();
這是最好的(最快/優雅的方式)?它可以做不同的事情嗎?
我的建議是更新你的模型有它的配置文件。它很有意義的它有.. – Baz1nga 2012-04-12 09:47:43
在我而言這不是一個選項。我知道...有點吮吸 – 2012-04-12 09:48:44