tags:

views:

183

answers:

1

I am using LinqToSql as you've seen on subject.

I've a table and some colums in it. There is one colum to show the state of record.

0 : Not approved yet
1 : Approved
2 : Deleted

When the record inserted at first, its value is 0 (default value). When user approved it its value is changing to 1 but i'm getting this error:

Value of member 'state' of an object of type 'News' changed.
A member that is computed or generated by the database cannot be changed.

This is the test code:

DataClassesDataContext dc = new DataClassesDataContext();
var b = dc.GetTable<Ekler>().Where(p => p.ek_id == 1).FirstOrDefault();
if (b!=null)
{
    b.state= "1";
    dc.SubmitChanges();
}

What should i do to pass this problem?

+1  A: 

You should look at the definition of the "state" column in the designer for the data context, and/or the database itself. Basically LINQ to SQL thinks this is something like an autogenerated value or one which is computed at the database - not something which should be hand-edited. If it should be manually updateable (which it sounds like), you need to tell that to LINQ to SQL.

Jon Skeet
I'm creating context class for my project by inheriting DataContext. So I'm manually writing every entity classes and their columns properties. I've changed it's IsDbGenerated attribute (actually i deleted). Now i can change its value without getting error but when i inserted new record to table, "state" column gets NULL value.
uzay95
@uzay95: Well, I would take a close look at everything you've specified in the data context - and what the generated SQL looks like. It definitely sounds like a problem in how you've set up the context.
Jon Skeet