开发者

A member that is computed or generated by the database cannot be changed

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

I've a table and some colums in it. There is o开发者_如何学运维ne 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?


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.


In my case is my mistake, by accidently I ticked the property - "Auto Generated Value" => True for the field in DBML design mode.

A member that is computed or generated by the database cannot be changed


I was facing the same problem when we try to update record in the database. we can insert but when we will try to update records with one of the computed column in the database, it gives an error like : "Value of member of an object of type changed. A member that is computed or generated by the database cannot be changed."

Solution : We cannot update that field in the database but we can edit reference field of the computed column which refers it.When we update reference field then computed column automatically update this field in the table.

Let me know if you have any further query.

Thanks..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜