Aaron Anodide
Aaron Anodide

Reputation: 17196

How do I merge sets of EF entities?

I would like to obtain records from two sources (i.e. 2 different connection strings) with identical model to storage mappings.

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?

Upvotes: 0

Views: 695

Answers (1)

CodingWithSpike
CodingWithSpike

Reputation: 43748

Do you mean that you want all of the 'Things' from both DBs in 1 list? If so, you can just use the Union() method I believe:

Change the last line to:

var allThings = set1.Union(db.Things);

Upvotes: 3

Related Questions