c# - EF Core 2.0 ThenInclude with WHERE -




there happen following relationship in db:

cartentry -> product -> producttext <- culture

so, every product, can set title, desc etc each supported culture. im switching stored procedures ef, , therefore have migrate sp items in cart localized name.

well, have feeling, isnt elegant:

public actionresult index(cartindexviewmodel vm)     {         vm.cart = db.cart             .include(cart => cart.product)                 .theninclude(pt => pt.producttext)                     .theninclude(c => c.culture)              .where(t => t.token == contexthelper.gettoken(httpcontext))             .tolist();          foreach (model.cart cart in vm.cart)         {             model.producttext pt = cart.product.producttext.first(n => n.culture.name == cultureinfo.currentculture.name.tolowerinvariant());              cart.product.title = pt.title;             cart.product.description = pt.description;             cart.product.link = pt.link;         }          return view(vm);     } 

is there more beautiful way of doing this? rid of foreach?

thank in advance!





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -