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# - 使用正则表达式解析特定的 CSS

c# - .NET开发人员如何看待条件运算符?

C# 不明确的调用 - 不同的返回类型

mysql - 删除SQL中的重复元素

mysql - 连接表时 'field list' 中的未知列 xxx(MySQL、MariaDB)

LINQ to Entities 无法识别方法 'System.DateTime AddSeconds(Double)' 方法,且此方法无法转换为

c# - 将按钮扩展到 UWP 中的标题栏

mysql - 合并为单个查询

c# - 实体数据模型向导太慢(SQL 数据库)

c# - 如何使用 EF 4 和 SQL Server CE 3.5 对查询结果进行分页