实体框架4.1代码优先KeyAttribute为非标识列 [英] Entity Framework 4.1 code-first KeyAttribute as non-identity column
问题描述
这是有关表的代码:
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屋!