views:

25

answers:

1

SQL Server Compact does not support identity column when it is used with the Entity Framework so I must generate the identity value manually. I did as follows:

        DatabaseEntities de = new DatabaseEntities();
        Income income = new Income();  
        income.Id = de.Incomes.Max(f => f.Id) + 1;
        income.Time = DateTime.Today;
        de.SaveChanges();

I think this is the simplest way but it is not success. I think my problem come from identity value generation. Please help me.

+1  A: 

There is no other way. But you can try something like this

http://blog.stpworks.com/archive/2008/05/30/ado.net-entity-framework-sqlce-and-identity-columns.aspx

nitropropain
I checked my way again and I saw it was success but when i closed my program then I did not see the data.
Linh