简体   繁体   中英

What's the difference between Projection and Join table in ASP.NET CORE

Are they the same thing? and which one is the better way to query data from several tables. I prefer using projection method more because it's quite simple.

Projection

https://benjii.me/2018/01/expression-projection-magic-entity-framework-core/

Join table

https://entityframeworkcore.com/querying-data-joining

Select is probably better if you're talking about Entity framework, if it's an option, and you're just following the foreign keys (ie Navigation Properties).

However, if you need to join using an unusual method, particularly on related data, then join is sometimes the better (or sometimes only) option.

For instance, getting a count of logins every day against a count of signups every day, would use a join, because login count and signup count are using two completely unrelated tables and joining on date, not userID.

Getting a list of activities belonging to all active users, you can do with a Select, because the "belonging to" relationship is represented by the FK.

Finally, don't forget Select allows you to take a subset of data from a single table, whereas join requires you to be joining two tables together to then filter to a subset.

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