[英]How do I merge sets of EF entities?
I would like to obtain records from two sources (ie 2 different connection strings) with identical model to storage mappings. 我想从两个来源(即2个不同的连接字符串)获得具有相同模型到存储映射的记录。
Something more-or-less like: 差不多:
var db = new MyModel(connectionString1);
var set1 = db.Things;
db = new MyModel(connectionString2);
set1.Merge(db.Things);
Is this possible? 这可能吗?
Do you mean that you want all of the 'Things' from both DBs in 1 list? 您是说要两个DB中的所有“物”都在列表中吗? If so, you can just use the
Union()
method I believe: 如果是这样,您可以使用我相信的
Union()
方法:
Change the last line to: 将最后一行更改为:
var allThings = set1.Union(db.Things);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.