简体   繁体   中英

What is the right and efficient way to retrieve data using Entity Framework 6

I have 2 tables:

T1
{
  Columns: **A**, B, C
}

T2
{
  Columns: D, E, F, **A**
}

T1 has one to many connection to T2 using a foreign key (column A ).

I'm trying to retrieve a list of F in case that A=1,B=2,E=3 .

What is the right and efficient way to retrieve this data?

  • Is it join statement?
  • Is it by retrieving all T1 (where A=1,B=2) including T2 and then looping over the result (and eliminate the irrelevant T2 )?
  • Some other way?
var lst = (from t1 in context.T1
        join t2 in context.T2 on t1.A equals t2.A
        where t1.A == 1 && t1.B == 2 && t2.E == 3
        select t2.F).ToList();
  • Join the tables
  • Filter in the where clause
  • Select just the one property you are interested in

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