c# - Include method in LINQ is used for Left Join? -


i'm using entity framework 6, dotconnect oracle , have these 2 queries:

first one, using simple join (linq , output sql):

linq:

var joinquery = db.products       .join(db.product_categories.asenumerable(), p => p.productid,          pc => pc.categoryid, (pc, p) => new { pc, p })     .tolist(); 

output sql:

select * products 

second, using include:

linq:

var includequery = db.products.include("product_categories").tolist(); 

output sql:

select * products      left outer join product_categories          on products.categoryid = product_categories.categoryid   



in doubt if can use "include" method left joins. method not clear my.

in first example join should not have .asenumerable() on end of it. doing causing ef go , records product_categories , doing join in memory can inefficient doesn't use kind of index.

the second option have isn't pure linq. include ef-specific extension method not available in other providers.

so if want common linq use other db providers go option 1. if want simpler syntax , okay being ef specific option 2 might better.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -