实体框架无效列(数据库或代码中不存在该列)
本文关键字:不存在 代码 数据库 框架 无效 实体 | 更新日期: 2023-09-27 17:56:32
所以我看到了很多像我这样的问题。 但是没有一个答案是有效的。每当我尝试更新实体时,我都会收到无效列异常:
[SqlException (0x80131904):列名"ssma$rowid"无效。 列名"ssma$rowid"无效。
这是从哪里来的?我已经重新生成/重建/清理/删除了表,但仍然出错。数据库没有具有此名称的列。 我该如何解决这个问题?
这是我的实体,它没有外键:
public interface IDataContext : IDisposable
{
IDbSet<Organization> Organizations { get; set; } // organizations
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new OrganizationConfiguration());
}
public partial class Organization : BaseEntity
{
public long Id { get; set; } // id (Primary key)
public long? ReportTypeId { get; set; } // report_type_id
public byte Active { get; set; } // active
public long? TimeZoneId { get; set; } // time_zone_id
public string Name { get; set; } // name
public string MainContact { get; set; } // main_contact
public string Address { get; set; } // address
public string City { get; set; } // city
public string StateId { get; set; } // state_id
public string StateName { get; set; } // state_name
public string ZipCode { get; set; } // zip_code
public string Phone { get; set; } // phone
public string Fax { get; set; } // fax
public string Email { get; set; } // email
public string Website { get; set; } // website
public short IncludeContactType { get; set; } // include_contact_type
public short NursingNote { get; set; } // nursing_note
public DateTime UpdatedAt { get; set; } // updated_at
public DateTime CreatedAt { get; set; } // created_at
public string OfficeBackline { get; set; } // officeBackline
public string Pharmacy { get; set; } // pharmacy
public string PharmacyPhone { get; set; } // pharmacyPhone
public string PharmacyBin { get; set; } // pharmacyBin
public string PharmacyGroup { get; set; } // pharmacyGroup
public string Dme { get; set; } // dme
public string DmePhone { get; set; } // dmePhone
public string LanguageLine { get; set; } // languageLine
public string LanguageLinePin { get; set; } // languageLinePin
public string Announcements { get; set; } // announcements
public string Skillname { get; set; } // skillname
public string OutboundSkill { get; set; } // outbound_skill
public string InboundSkill { get; set; } // inbound_skill
public string Dnis { get; set; } // dnis
public byte[] Logo { get; set; } // logo
public Organization()
{
Active = 1;
StateId = "NULL";
StateName = "N''";
NursingNote = 0;
UpdatedAt = DateTime.Now;
OfficeBackline = "NULL";
Pharmacy = "NULL";
PharmacyPhone = "NULL";
PharmacyBin = "NULL";
PharmacyGroup = "NULL";
Dme = "NULL";
DmePhone = "NULL";
LanguageLine = "NULL";
LanguageLinePin = "NULL";
Skillname = "NULL";
OutboundSkill = "NULL";
InboundSkill = "NULL";
Dnis = "NULL";
}
}
以下是配置:
// organizations
internal partial class OrganizationConfiguration : EntityTypeConfiguration<Organization>
{
public OrganizationConfiguration()
{
ToTable("dbo.organizations");
HasKey(x => x.Id);
Property(x => x.Id).HasColumnName("id").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(x => x.ReportTypeId).HasColumnName("report_type_id").IsOptional();
Property(x => x.Active).HasColumnName("active").IsRequired();
Property(x => x.TimeZoneId).HasColumnName("time_zone_id").IsOptional();
Property(x => x.Name).HasColumnName("name").IsRequired().HasMaxLength(255);
Property(x => x.MainContact).HasColumnName("main_contact").IsRequired().HasMaxLength(255);
Property(x => x.Address).HasColumnName("address").IsRequired().HasMaxLength(255);
Property(x => x.City).HasColumnName("city").IsRequired().HasMaxLength(255);
Property(x => x.StateId).HasColumnName("state_id").IsOptional().HasMaxLength(5);
Property(x => x.StateName).HasColumnName("state_name").IsRequired().HasMaxLength(255);
Property(x => x.ZipCode).HasColumnName("zip_code").IsRequired().HasMaxLength(255);
Property(x => x.Phone).HasColumnName("phone").IsRequired().HasMaxLength(255);
Property(x => x.Fax).HasColumnName("fax").IsRequired().HasMaxLength(255);
Property(x => x.Email).HasColumnName("email").IsRequired().HasMaxLength(255);
Property(x => x.Website).HasColumnName("website").IsRequired().HasMaxLength(255);
Property(x => x.IncludeContactType).HasColumnName("include_contact_type").IsRequired();
Property(x => x.NursingNote).HasColumnName("nursing_note").IsRequired();
Property(x => x.UpdatedAt).HasColumnName("updated_at").IsRequired();
Property(x => x.CreatedAt).HasColumnName("created_at").IsRequired();
Property(x => x.OfficeBackline).HasColumnName("officeBackline").IsOptional().HasMaxLength(50);
Property(x => x.Pharmacy).HasColumnName("pharmacy").IsOptional().HasMaxLength(255);
Property(x => x.PharmacyPhone).HasColumnName("pharmacyPhone").IsOptional().HasMaxLength(50);
Property(x => x.PharmacyBin).HasColumnName("pharmacyBin").IsOptional().HasMaxLength(50);
Property(x => x.PharmacyGroup).HasColumnName("pharmacyGroup").IsOptional().HasMaxLength(255);
Property(x => x.Dme).HasColumnName("dme").IsOptional().HasMaxLength(255);
Property(x => x.DmePhone).HasColumnName("dmePhone").IsOptional().HasMaxLength(50);
Property(x => x.LanguageLine).HasColumnName("languageLine").IsOptional().HasMaxLength(255);
Property(x => x.LanguageLinePin).HasColumnName("languageLinePin").IsOptional().HasMaxLength(50);
Property(x => x.Announcements).HasColumnName("announcements").IsOptional();
Property(x => x.Skillname).HasColumnName("skillname").IsOptional().HasMaxLength(255);
Property(x => x.OutboundSkill).HasColumnName("outbound_skill").IsOptional().HasMaxLength(30);
Property(x => x.InboundSkill).HasColumnName("inbound_skill").IsOptional().HasMaxLength(30);
Property(x => x.Dnis).HasColumnName("dnis").IsOptional().HasMaxLength(30);
Property(x => x.Logo).HasColumnName("logo").IsOptional();
}
}
和数据上下文类
public partial class DataContext : DbContext, IDataContext
{
public override int SaveChanges()
{
var changedEntities = ChangeTracker.Entries();
foreach (var changedEntity in changedEntities)
{
if (changedEntity.Entity is BaseEntity)
{
var entity = (BaseEntity)changedEntity.Entity;
switch (changedEntity.State)
{
case EntityState.Added:
entity.OnBeforeInsert();
break;
case EntityState.Modified:
entity.OnBeforeUpdate();
break;
case EntityState.Deleted:
entity.OnBeforeDelete();
break;
}
}
}
var results = base.SaveChanges();
return results;
}
}
这不是实体框架问题。 这是数据库中的东西,可悲的是,这是您没有向我们提供任何详细信息的部分,甚至没有提供它是哪个RDBMS。
听起来你有一个从其他RDBMS迁移而来的SQL Server数据库。
我怀疑问题源于对ssma$rowid
列的引用的表触发器之一。 浏览触发器以查看是否可以找到此问题,并根据需要进行修复。
此ssma$rowid
列听起来像是迁移数据库时遗留下来的列。
我希望这有所帮助。 如果您添加有关表、触发器、数据库等的更多详细信息,我们可能会为您提供进一步的帮助。
该列由 Oracle 到 SQL 转换器生成。
该错误可能与映射有关(这是您拥有的唯一映射吗?你没有任何DBFirst文件吗?或者像@sstan建议的那样仍在数据库中。