实体框架4.1代码优先KeyAttribute为非标识列 [英] Entity Framework 4.1 code-first KeyAttribute as non-identity column

查看:131
本文介绍了实体框架4.1代码优先KeyAttribute为非标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遇到了一个代码优先模型的问题。数据现在在数据库中,所以我无法使用DropCreateDatabaseIfModelChanges类重新种子数据库,但是我需要更改一个表,以便一个bigint列不是IDENTITY(1,1)。我已经设法使用SSMS,但现在我的EF代码说它已经过时了。
这是有关表的代码:

  public class Vote {
[必需,键,DatabaseGenerated(DatabaseGeneratedOption.None)]
public long FacebookUserId {get;组; }
[必需]
public Entity Entity {get;组; }
}

所以我改变了我的表模式和我的模型思想是它的反映,但我显然是错误的),但是EF仍然在说我的模型已经过时了,我无法重新种子数据库来使其完美。



任何帮助将不胜感激。



谢谢,



本杰明

解决方案

尝试将其添加到您的 OnModelCreating

  modelBuilder.Conventions.Remove< IncludeMetadataConvention>(); 

应该删除模型已经过期的异常,但是直到这时候你必须始终同步模型和数据库手动。


I've got a problem with a code-first model I've got. Data is now in the database so I can't re-seed the database using a DropCreateDatabaseIfModelChanges class, but I need to change one table so that a bigint column is not an IDENTITY(1,1). I've managed to do this using SSMS but now my EF code is saying it's out of date. This is the code for the table in question:

public class Vote {
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public long FacebookUserId { get; set; }
    [Required]
    public Entity Entity { get; set; }
}

So I've changed my table schema, and my model (which I thought was the reflection of it, but I'm obviously wrong), but EF is still saying my model is out of date, and I can't re-seed the database to get it "perfect".

Any help would be much appreciated.

Thanks,

Benjamin

解决方案

Try add this to your OnModelCreating:

modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

That should remove the exception that model is out of date but till this time you must always synchronize model and database manually.

这篇关于实体框架4.1代码优先KeyAttribute为非标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆