c# - Simple update with Entity Framework -


i have following code , cannot achieve saving changes. parameter of method string containing refcode of product want modify in database, query pulling baseproduct supposed modified. (i tried simplify code , set in english, have introduced syntactic errors, in code in debug mode, info db). there wrong "select new" in linq query ?

public static void updateproduct(viewproduct producttoupdate)     {         using (var context = new my_entities())         {             var baseproduct = (from prod in context.product                                prod.ref == producttoupdate.baseproduct.refprd                                       select new viewbaseproduct                                       {                                           refprd = prod.ref,                                           descrprd = prod.descrprd,                                           normece = (bool)prod.normece                                       }).firstordefault();              if (baseproduct != null)             {                 //baseproduct.normece = false;                 baseproduct = producttoupdate.baseproduct;                 context.savechanges();             }         }     } 

but baseproduct viewbaseproduct object, viewbaseproduct entity class? seems viewmodel class.

you have de product entity, modify fields , savechanges. seems apply changes viewmodel class.

try this:

public static void updateproduct(viewproduct producttoupdate) {     using (var context = new my_entities())     {         var baseproduct = (from prod in context.product                            prod.ref == producttoupdate.baseproduct.refprd)                           .firstordefault();          if (baseproduct != null)         {             //baseproduct.normece = false;             baseproduct.field1 = producttoupdate.baseproduct.field1;             baseproduct.field2 = producttoupdate.baseproduct.field2;              //update necesary fields             //......             context.savechanges();         }     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -