开发者

Generating Integer Identity Primary Key for Entity Object in Entity Framework and SQL Server CE

开发者 https://www.devze.com 2023-01-16 11:13 出处:网络
I heard that this issue is fixed in SQL Server Compact Edition 4.0 CTP As recently 开发者_JAVA百科I just stepped into SQL Server CE and Entity Framework, and VS2010 not yet supporting SQL Server CE 4

I heard that this issue is fixed in SQL Server Compact Edition 4.0 CTP

As recently 开发者_JAVA百科I just stepped into SQL Server CE and Entity Framework, and VS2010 not yet supporting SQL Server CE 4.0

I think I would need a work around for this issue

Can I know how to generate an Integer type Identity Primary Key inside the constructor of the Entity Object

   public partial class Book 
 {

  public Book()
  {
   // SQL Server Compact does not support entities with server-generated keys or values when it is used 
   // with the Entity Framework. Therefore, we need to create the keys ourselves.


   Id = // Generating a Integer Identity Id here
     //similar to Guid.NewGuid();

  }
}

Your help is much appreciated.


I've used VS2010 and SQL Server CE with Entity Framework CTP4 Code-First and it worked with no problems. I've installed both thing using NuPack (now NuGet - http://nuget.codeplex.com/) and used it with ASP.NET MVC 3 Beta application.

The latest version of SQLCE on NuGet is 4.0.8435.1 and to use it with EF you have SQLCE.EntityFramework 4.0.8435.1 on there.


I met same problem, I take max value of the Id column after that add one. If you are developing a desktop application you should mind problem in the following link:Problem when inserting data into SQL Compact by ADO.Net Entity Framework


This is exactly what I'm looking for:

// SQL Server Compact does not support entities with server-generated keys or values when it // with the Entity Framework. Therefore, we need to create the keys ourselves.

so we have to generate our id (int) manually instead of auto generating it from SQL Server Compact.

0

精彩评论

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