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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -