c# - SubmitChanges not updating -


first of precise read related subjects submitchanges issues couldn't find solving problem... have several tables working fine using same way (excepting composite primary keys) 1 doesn't, can't understand why. here's table :

create table [dbo].[trainings] (     [playerid] int not null,     [stepid]  int not null,     [value]   int not null,     constraint [pk_trainings] primary key clustered ([playerid] asc, [stepid] asc) ); 

the related class :

[table(name = "trainings")] public class training {     [column(isprimarykey = true)] public int playerid { get; set; }     [column(isprimarykey = true, name = "stepid")] public int step { get; set; }     [column] public int value { get; set; }      public training(int playerid, int step, int value)     {         playerid = playerid;         step = step;         value = value;     } } 

and database update call :

public class database : datacontext {     public table<training> trainings;      public training gettraining(int playerid, int step)     {         training training = trainings.where(t => t.playerid == playerid && t.step == step).single();         return training;     }      public void updatetraining(training training)     {         training dbtraining = gettraining(training.playerid, training.step);         dbtraining = training;         submitchanges();     } } 

i tried remove composite primary keys , add "id" key table not updated anyway. way found make work delete old row , add new 1 new value, horrible.

when tried put break point in it, got error message doesn't show on normal mode :

the operation cannot performed during call submitchanges.

edit:

seems problem due sql exception. here's exception tracktrace :

system.exception.stacktrace.get system.data.linq.datacontext.checknotinsubmitchanges() system.data.linq.datacontext.submitchanges(conflictmode failuremode) system.data.linq.datacontext.submitchanges() database.updatetraining(training training) 

you not making changes. line of code assign local variable dbtraining new value:

dbtraining = training; 

what want this:

dbtraining.value = training.value 

that update value of current instance in database. saved when call submitchanges.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -