Entity Framework / SQL Server Include behaviour with filtering -


i have 2 basic questions regarding ef , sql server ask along examples.

  1. say have following query:

    db.customers.include(c => c.orders)         .include(c => c.items)         .include(....).where(c => c.age > 25) 

    in simple query retrieve customers based on condition , related data other tables. includes (joins) happen on records in database first , these filtered on condition or first engine filter records without joining , perform joins on filtered records? question concerns ef far generated query maybe , sql server query engine too.

  2. what behaviour if of properties used in includes part of filtering? again all joins performed on every record in database or perform needed joins filtering on records in database , remaining joins on filtered records? situation can described like:

    db.customers.include(c => c.orders)         .include(c => c.items)         .include(....).where(c => c.orders.any(o.name.startswith("football") 

    also how behaviour differs if no navigation properties used in filtering (as in question 1)?

no, include not filter related objects based on filters provided. because both different operations. in case have use projections.

db.customers.include(c => c.orders)     .include(c => c.items)     .include(....).where(c => c.orders.any(o.name.startswith("football") 

above query give different results query projection shown below,

db.customers     .include(c => c.items)     .include(....).select(c => new {          customer = c,          orders = c.orders.where( o => o.name.startswith("football")     }) 

i have removed include orders, have created projection orders.

in first case there no join where clause, use exists clause , include use join records.

in second case perform join results filter, perform join on filter specified in projection.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -