简体   繁体   中英

Entity Framework joining tables from two different entities

I'm working on a project with over 15 databases, I need always to join tables from different entities so I end up using .ToList .

I had an advice from a friend to do a database link-server and then to create views in the same database for all the references tables.

But I'm not happy with both of them.

Is there any alternative solution other than .ToList & database views and what is the best practice in this case?

Plenty of ways around this, each with their own disadvantages.

Linked databases with views

Check the usage on the Microsoft docs

The ability to access data from outside of SQL Server.

The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.

The ability to address diverse data sources similarly.

Point three is your case exactly. You also have the ability to link multiple databases like mysql if need be.

A lot of disadvantages though ( check here ). I will add one of my own and say that

Implement with code and automapper

If all the tables are similar, then you can use a tool like automapper to make easy lists from your data

  1. Get your data with entity framework
  2. Map to DTO objects with the common properties using automapper
  3. Merge your lists with Range add.

Duplicate data

We live in a world were nosql solutions are used alongside RDBMS solutions. it might be that you create a common db (RDBMS or nosql or whatevers suits you), and duplicate your data there.

It's extra work but it's the fastest in usage.

I could think of more, but this is the gist of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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