c# - Entity Framework - Table structure, navigating many descendants, etc -




so i'm rewriting dated application , trying structure things right way. have category > product > part > options basic structure, there multiple layers in each , don't know how simplify data structure, , navigate children effectively.

table structure

i feel it's little complicated e-commerce, have multitude of product, part, , part options.

so kicks tried see if round data top level category way down swatches different part options see if entire page display entire category/product line @ once (i know not in production). immediate problem ran including descendants in linq queries, there several require intermediary objects due columns in relational tables. that's necessary, understand, gets messy setup have potentially unlimited number of category/subcategory levels. example:

iqueryable<category> categories = context.categoryhierarchies     .where(w => w.parentcategoryid == null)     .where(w => w.active == true)     .orderby(o => o.sort)     .select(s => s.category)     .include("parentcategories")     .include("categoryproducts.product.productparts.part")     .include("subcategories.category.categoryproducts.product.productparts.part")     .include("subcategories.category.subcategories.category.categoryproducts.product.productparts.part") 

i didn't lambas on includes keep things shorter paste. go on longer didn't part options, there, potentially need have 3 more lines each level of part option, right? like:

.include("subcategories.category.categoryproducts.product.productparts.part.partmaterials.swatch") 

all way down. yikes. question, when i'm loading viewmodels view, , want access categories, products, , potentially parts, there better way this? have view foreach on each level can, starts getting tedious real fast. load them separate objects in view model , access them directly, , populated through separate queries? i'm pretty new , appreciate anyone's suggestions.

i did see .net core .theninclude() stuff, helpful, wasn't sure clean things much. it's lot of descending.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

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

python - Read npy file directly from S3 StreamingBody -