我需要你的帮助。每次进行选择时,我总是收到错误“无效的列名'鉴别器'”。奇怪的是,我的映射或表格中没有任何鉴别器列。我尝试[NotMapped]
在我的类中添加(如此处所述:EF Code First “Invalid column name 'Discriminator'”但没有继承)但无济于事。
以下是我触发错误的代码。
模型
public class MasterUser : IAuditFields
{
[Key]
public string Username { get; set; }
public string Name { get; set; }
public string GroupID { get; set; }
public string Status { get; set; }
public string DeptID { get; set; }
public string Rank { get; set; }
public string CreatedBy { get; set; }
[Required]
public DateTime CreatedDate { get; set; }
public string LastModifiedBy { get; set; }
public DateTime? LastModifiedDate { get; set; }
#region Relationships
public UserAccess UserAccess { get; set; } // User needs to see what user access group he/she is in
public UserAccessDetail UserAccessDetail { get; set; } //User needs to see what he/she can do
#endregion
}
界面
public interface IAuditFields
{
string CreatedBy { get; set; }
DateTime CreatedDate { get; set; }
string LastModifiedBy { get; set; }
DateTime? LastModifiedDate { get; set; }
}
配置类
public class MasterUserConfig : EntityTypeConfiguration<MasterUser>
{
public MasterUserConfig()
{
Property(usr => usr.Username)
.HasColumnName("UserName")
.IsRequired();
Property(usr => usr.Name).HasColumnName("Name");
Property(usr => usr.GroupID).HasColumnName("GroupId");
Property(usr => usr.Status).HasColumnName("Status");
Property(usr => usr.DeptID).HasColumnName("DeptId");
Property(usr => usr.Rank).HasColumnName("Rank");
Property(usr => usr.CreatedBy).HasColumnName("CreatedBy");
Property(usr => usr.CreatedDate).HasColumnName("CreatedDate");
Property(usr => usr.LastModifiedBy).HasColumnName("LastModifiedBy");
Property(usr => usr.LastModifiedDate).HasColumnName("LastModifiedDate");
ToTable("dbo.Users");
}
数据上下文
public class BBDataContext : DbContext
{
public DbSet<MasterUser> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
try
{
modelBuilder.Configurations.Add(new MasterUserConfig());
base.OnModelCreating(modelBuilder);
}
catch (Exception ex)
{
DiagnosticHelper.Message = ex.Message;
DiagnosticHelper.InnerException = ex.InnerException.Message;
DiagnosticHelper.StackTrace = ex.StackTrace;
DiagnosticHelper.Instance.WriteError();
}
}
}
选择方法
public MasterUser GetUserByUsername(string userName, string password)
{
try
{
return (_context.Users
.Where(usr => usr.Username == userName && usr.Password == password && usr.Status == "ACTIVE"))
.SingleOrDefault();
}
catch (Exception ex)
{
LogError(ex);
}
return null;
}
希望您能够帮助我。非常感谢!