c# - How to handle pivoting POCOs? -
i have poco based off normalized table. question how handle changing not pivoted/normalized object de-normalized/pivoted object? need create poco pivoted version? how 1 handle this?
let's pretend normalized poco defined as:
customer table
customerid int bestseller bool numberoforders int and want represent as
pivot customer table
customerid int bestsellerorders int notbestsellerorders int update
this works, not sure it:
public void updatecustomer(customerpivot customerpivot) { using (var context = dataobjectfactory.createcontext()) { // find rows update (2) var rowstoupdate = context.customer .where(w => w.customerid == customerpivot.customerid).tolist(); var first = rowstoupdate.where(w => w.bestseller == true).singleordefault(); var second = rowstoupdate.where(w => w.bestseller == false).singleordefault(); first.numberoforders = (int)customerpivot.bestsellerorders; second.numberoforders = (int)customerpivot.notbestsellerorders; context.customer.applychanges(first); context.customer.applychanges(second); context.savechanges(); } }
yes new readonly entity mapped database view defining pivoted query or new custom object used materialized result of custom sql query executed executestorequery because using pivoting in sql server easier , faster.
Comments
Post a Comment