简体   繁体   English

如何合并EF实体集?

[英]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.

相关问题 如何序列化实体框架实体(EF 5.0)? - How do I serialize Entity Framework entities (EF 5.0)? 首先使用数据库时如何防止EF6合并实体? - How to prevent EF6 to merge entities when using database first? 如何从Web API JSON响应中的相关EF实体中删除属性 - How do I remove properties from related EF entities in Web API JSON response 如何使用EF4 Code-First一次创建两个关联实体 - How do I create two associated entities at one time with EF4 Code-First 如果实体之一不引用另一个实体,如何在 EF Core 中配置一对一关系? - How do I configure one-to-one relationship in EF Core if one of entities does not reference the other one? 如何关联来自我的实体的数据? ASP.NET MVC 5 EF 6 - How do I relate the data from my entities? ASP.NET MVC 5 EF 6 如何进行EF Linq查询,包括相关实体的子集 - How can I do an EF Linq query, including a subset of related entities 如何停止EF RIA服务,以保存相关实体上的更改? - How do I stop EF RIA services saving changes on related entities? 如何基于 EF Core(无密钥实体)中的查询创建对象? - How do I create objects based on a query in EF Core (keyless entities)? 如何从 EF Core 中的父实体中删除子项? - How do you delete Child from Parent entities in EF Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM