列名无效:带有后缀编号的“ColumnName#”

时间:2017-09-06 18:40:29

标签: c# entity-framework entity-framework-6

我有一张表Users

enter image description here

我正在使用Entity Framework 6进行类型配置

public class UsersMapping : EntityTypeConfiguration<Users>
{
    public UsersMapping()
    {
        HasKey(t => t.UserID);
        Property(t => t.UserID).IsRequired();

        ToTable("Users", "dbo");

        Property(t => t.Id).HasColumnName("UserID");
    }
}

这是Users类:

public class Users : EntityBase
{
    public int UserID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string UserName { get; set; }
    public DateTime DateCreated { get; set; }
    public byte[] Timestamp { get; set; }
    public byte[] Password { get; set; }
    public DateTime? DateActivated { get; set; }
    public bool LockedOut { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public int? State { get; set; }
    public string Zip { get; set; }
    public string SecurityQuestion { get; set; }
    public string SecurityAnswer { get; set; }
    public string Email { get; set; }
    public string PhoneNumber { get; set; }
    public bool? ReportServiceAccount { get; set; }
    public string CompanyName { get; set; }
    public int? ILAC { get; set; }
    public string BioFingerprint { get; set; }
    public string Title { get; set; }
    public string Squad { get; set; }
    public byte[] SignatureFile { get; set; }
    public byte? CETGroupID { get; set; }
    public string TokenID { get; set; }
    public int? Pin { get; set; }
    public string RadioNr { get; set; }
}

public class EntityBase
{
   public int Id { get; set; }
}

我正在尝试将Id字段设置为主要字段,因为我的存储库模式使用表中此案例中不存在的字段Id。但是当我试图获得这组用户时,我得到了这个错误:

  

列名称无效UserID1

对我来说奇怪的是最后的#1。我做错了什么?

0 个答案:

没有答案