c# - What is the best way to query entities with n-to-m relations with Dapper -
this part of data model in sql server:
- product
- id
- name
- ...
- productvariety
- id
- name
- ...
- order
- id
- ...
- order_ref_product
- id
- order_id
- product_id
- ...
- order_ref_product_ref_variety
- order_ref_product_id
- productvariety_id
my c# poco classes (i removed of clutter {get;set;} etc. simplicity):
class order { list<product> products } class product { string name list<productvariety> varieties } class productvariety { }
for querying these via dapper, created 3 repositories, call each other recursively:
- orderrepository
- selects single order id
- then calls productrepository resolve products list.
- productrepository
- selects join of order_ref_product + product order_id
- then calls productvarietyrepository each object resolve varieties list.
- productvarietyrepository
- selects join of order_ref_product_ref_variety + productvariety order_ref_product_id
this works, however, i wonder if there better / cleaner / more performant way query object tree using dapper.
Comments
Post a Comment