c# - 在 Entity Framework 和 SQL Server CE 中为实体对象生成整数标识主键

标签 c# sql entity-framework-4 sql-server-ce compact-database

听说 SQL Server Compact Edition 4.0 CTP 中修复了这个问题

最近刚接触SQL Server CE和Entity Framework,VS2010还不支持SQL Server CE 4.0

我想我需要解决这个问题

我能知道如何在实体对象的构造函数中生成一个整数类型的身份主键

   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();

  }
}

非常感谢您的帮助。

最佳答案

我已经将 VS2010 和 SQL Server CE 与 Entity Framework CTP4 Code-First 一起使用,并且没有任何问题。我已经使用 NuPack(现在是 NuGet - http://nuget.codeplex.com/)安装了这两个东西,并将其与 ASP.NET MVC 3 Beta 应用程序一起使用。

NuGet 上最新版本的 SQLCE 是 4.0.8435.1,要将它与 EF 一起使用,您需要 SQLCE.EntityFramework 4.0.8435.1。

关于c# - 在 Entity Framework 和 SQL Server CE 中为实体对象生成整数标识主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3739304/

相关文章:

c# - 创建具有特定间距(使用\t)的字符串变量,类似于 Console.WriteLine

sql - PostgreSQL 通过 GROUP BY 删除重复项

c# - Entity Framework 4 : What causes . Take(10) 返回 20 条记录?

sql - 在通过 sql server 作业执行 ssis 包的运行时将 run 64 位运行时属性更改为 false

mysql - 根据经纬度查找用户

c# - 如何通过 Entity Framework 存储可变二维数组?

c# - 使用模型类的 Asp.net MVC 下拉列表绑定(bind)

c# - Windows.Forms 助记符不起作用

c# - 发生ajax回发时下拉列表丢失元素样式

c# - 使用字符串数组动态填充功能区设计组合框?