Click here to Skip to main content
15,032,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'am trying to create an update method in a generic repository as a data access layer
i have an entity like this:
C#
[Table]
public class Product
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "Int NOT NULL IDENTITY")]
    public int Id { get; private set; }
    [Column(UpdateCheck = UpdateCheck.Never)]
    public string Name { get; set; }
    ....
}


i set `Update Check = true` for all the fields exept for the id and i set the `asModified` propery in the attach method to true which i found as following:
C#
    public void Update(T entity)
    {
        _db.GetTable<t>().Attach(entity, true); 
        _db.SubmitChanges();
    }
</t>


but i keep getting the same exception:

An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

so what's the problem ???
or Do you recommend any other approches to create an update method in a generic repository except createing a timestamp column as a version number.

Thanks in Advance;
Posted

1 solution

include a timestamp column in that table. that will do it. I mean the timestamp data type. u can call it whatever u want, for eg. ts.

Else i sugesst you take a look at Disconnected Entity Change Tracking for LINQ: http://linq2sqleb.codeplex.com/[^]

Thx
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900