简体   繁体   中英

Entity Framework 5 Lambda Queries

I currently have the following data model, and I would like to run some Entity Framework 5 queries on it:

SecurityCollection( A_id, name, description)

SecurityIds( B_id, name, description)

PureJunctionTable( A_id, B_id)

UsersAssignedToSecurity(B_id, E_id, name)

Users(E_id, name,number)

I would like to get all SecurityCollection assigned to a user with id 123.

Entity Framework 5 does not create the Data Model for PureJunctionTable because it only consists of foreign keys.

I am looking to write this query in either Linq or Lambda Expressions.

For arguments sake lets keep the table names the same.

I can write the SQL Statement no problem but I am having a very hard time trying to put that into Entity Framework 5 Lambda expressions.

Thanks

The PureJunctionTable should be represented in the edmx as a relationship between SecurityCollection and SecurityIds, which manifests itself as a collection of SecurityCollections on SecurityIds and a collection of SecurityIds on SecurityCollection.

Without having all the objects created locally I can't guarantee the following is 100% accurate, but your expression would be something like:

context.Users
    .Include( "SecurityIds" )
    .Include( "SecurityCollections" )
    .Where( u => u.E_id == 123 );

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