没有找到方法HasDatabaseGeneratedOption [英] Method not found HasDatabaseGeneratedOption
问题描述
我已阅读与此相关的所有职位,我已经试过所有,但没有结果。
I have read all post related to this and i've tried them all but not results.
即时通讯使用流畅的API来我的模型映射到数据库。但是,当IM查询我得到这个错误:
Im using fluent api to map my models to the database. But when im query i get this Error:
Method not found:
'System.Data.Entity.ModelConfiguration.Configuration.DecimalPropertyConfiguration
System.Data.Entity.ModelConfiguration.Configuration.DecimalPropertyConfiguration.HasDatabaseGeneratedOption(System.Nullable`1<System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption>)'.
我的模型是这样的:
My model look like this:
ToTable("table_name");
HasKey(x => x.CounterId)//this property IS NOT NULLABLE
.Property(x => x.CounterId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.HasColumnName("dbCounter_Id")
.HasPrecision(10, 0)
.IsRequired();
Property(x => x.HouseId)
.HasColumnName("dbHouseId");
Property(x => x.ApplicationId)
.HasColumnName("dbApplication_id");
由于某些原因 .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
是给我这个错误,所以当我退出吧:
For some reason .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
is giving me this error so when i quit it:
HasKey(x => x.CounterId)
.Property(x => x.PageId)
.HasColumnName("dbCounter_Id")
.HasPrecision(10, 0)
.IsRequired();
我得到没有错误,但作为即时通讯幸运的地狱 当我尝试将记录添加到该表我得到<一个href=\"http://stackoverflow.com/questions/637121/linq-to-sql-why-am-i-getting-identity-insert-errors\">insert身份例外。我无法不加入,也没有退出它的 HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
方法。
I get not error but as im lucky as hell, when im trying to add a record to that table i get insert identity exception. I cant neither added nor quit it the HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
method.
要点:关键 CounterId
不是类型INTEGER,为DECIMAL(10,0)代替。莫非是这里的问题?由于在生产大量的应用程序,这将是在最坏的方式影响我不能改变列的数据类型。
Important: The key CounterId
is not type INTEGER, is DECIMAL(10,0) instead. Could that be the problem here? I cannot change the datatype of the column since there are a lot of app in production that will be affect in the worst way.
希望我能得到任何帮助。
Hope i can get any help.
推荐答案
您应该让这样
ToTable("table_name");
HasKey(x => x.CounterId); // you should split HasKey from Property
Property(x => x.CounterId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.HasColumnName("dbCounter_Id")
.HasPrecision(10, 0)
.IsRequired();
Property(x => x.HouseId)
.HasColumnName("dbHouseId");
Property(x => x.ApplicationId)
.HasColumnName("dbApplication_id");
这篇关于没有找到方法HasDatabaseGeneratedOption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!