简体   繁体   English

Linq to SQL Join IQueryable设置某些属性

[英]Linq to SQL Join IQueryable Set Certain Property

Is this possible? 这可能吗?

Let's say I had a simple IQueryable join like below: 假设我有一个简单的IQueryable连接,如下所示:

            var x = from t1 in Repo.GetThing1()
                    join t2 in Repo.GetThing2() on t1.Key equals t2.Key
                    select t1).ToList();

But let's there is a field on t1 that I want to set with t2. 但是让我在t1上有一个我想用t2设置的字段。 However I don't want to re-map all the fields from t1, I just want the ability to map that particular field in t1 from t2... 但是我不想重新映射来自t1的所有字段,我只想要能够在t1中映射t1中的特定字段...

Sure: 当然:

var query = from t1 in Repo.GetThing1()
            join t2 in Repo.GetThing2() on t1.Key equals t2.Key
            select new { Existing = t1, NewValue = t2.SomeField };

var list = query.ToList();

foreach (var pair in list)
{
    pair.Existing.SomeField = pair.NewValue;
}

(Then you can do whatever you want, of course.) (当然,你可以做任何你想做的事。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM