Given a list of A and a list of B, we want to "join" the two and put the results into C. The join should include everything from A and B, and indicate with a derived field whether its in A or B. It's this joined list that would be persisted into C.

Note: Each of these lists represent sql tables and the corresponding entities and their FK relations. Each table has more or less the same fields with the same datatypes. The difference however, is that some records will be in A but not in B, some in both etc.

My approach: Create a list of POCO classes that each list of A and B are selected and projected into. Then using LINQ (linq to objects, not linq to ef in this case), since we now simply would have two lists of objects. Join these lists into a new list. Select from this list, creating our destination entities, C. Finally, call savechanges to persist to the Db.

Assuming the problem is clear enough - is there a better approach or design pattern I can tap into that addresses this problem?

[ update ]
In other words, I am planning to join (eg. link ) the two lists together into a result list. From this result, I will project the results into a new list that represent the destination entities. Once that destination list is created. I should be able to simply add to the DbContext and call save changes.

  • It's not clear whether you are really trying to 'join' the results from A or B or just 'union' them. Your description of what you need to do suggests maybe the former but the solution you propose seems to do the latter. – JimmyJames Mar 7 at 18:24
  • Consider using SQL UNION or UNION ALL and a possibly a stored procedure. – NoChance Mar 7 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.