0

So I have seen a lot of questions like mine. But none of the answers are working. Anytime I try to update the entity I get an Invalid Column exception:

[SqlException (0x80131904): Invalid column name 'ssma$rowid'. Invalid column name 'ssma$rowid'.]

Where is this coming from? I have regenerated/rebuilt/cleaned/dropped table and still it errors. The database has no column with this name. How do I fix this?

Here is my entity, it has no foreign keys:

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";
    }
}

Here is the configuration:

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

And the datacontext class

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;
    }
}    
0

2 Answers 2

1

This is not an Entity Framework problem. It's something in the database, which sadly, is the part you have not given us any details about, not even which RDBMS it is.

It sounds like you have a SQL Server database that was migrated from some other RDBMS.

I suspect that the problem originates from one of the table triggers having a reference to this ssma$rowid column. Go through the triggers to see if you can find this, and fix as required.

This ssma$rowid column sounds like a left over from whenever your database was migrated.

I hope this helps. If you add more details about your tables, triggers, database, etc, we may be able to help you further.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the tip! There was a trigger that had added in the ssma$rowid on its own from the migration. Removed that and it worked perfect.
0

The column is generated by the Oracle to SQL converter.
The error could be related to mapping (is this the only mapping you have? Don't you have any DBFirst file?) or to something still in database like suggested by @sstan.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.