HasDatabaseGeneratedOption

HasDatabaseGeneratedOption

本文介绍了方法未找到HasDatabaseGeneratedOption的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读所有与此相关的帖子,我已经尝试过所有但不是结果。

I have read all post related to this and i've tried them all but not results.

我使用流畅的api将我的模型映射到数据库。但是当我查询我得到这个错误:

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>)'.

我的模型如下所示:

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

我没有错误但像地狱一样幸运当我尝试添加一个记录到该表时,我得到。我不能添加或退出 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.

重要提示:键code> 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.

希望我能得到任何帮助。 p>

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 09:54