DDD and Entity Framework: Pulling children from aggregate root -


this 1 driving me nuts! simplicity, i'm not gonna put entire code used our ddd expose i've tried , explain isn't working.

i have simple database structure:

products (holds product data)
orders (holds entered orders)
orderproducts (ref table between orders , product)

i have order aggregate root , want pull out product count of 1 simple order.

i fetch order id results in ef lambda:

var order = _orderrepository.get(orderid);     

then, try pull count of products in order using:

var count = order.orderproducts.count(); 

this line chokes when order has lot records because, it's fetching of them. fine. so, i'm refining bit adding filters products want count within order. product has couple of properties include type (so, there's type id). so, i'm trying this:

//this trimming down results dozen products) var count = order.orderproduct                  .where(op=>op.product.typeid == 2)                  .count();   

if use linqpad see kind of sql generated, surprise, it's still loading orderproducts order!

how can force apply filter in query directly?

it's loading of them because once touch navigation property (i.e. order.orderproducts) eager loading kicks in , loads of them (i.e. ones don't want). option reduce query database given orderid. maybe like:

_orderproductrepository.where(p => p.orderid == orderid && p.product.typeid == 2); 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -