I have a "base" entity with some properties that's being used by a bunch of other stuff (repository patterns, queues, etc) in some shared libraries. Mapped to a pluralized table.
I need to add a property to it for my specific implementation, and I want to reuse all the rest of the normal behaviors.
I derive a class:
public interface IItem {
[Key]
Guid Id { get; set; }
string Name { get; set; }
}
public class Item : IItem {
[Key]
public Guid Id { get; set; }
public string Name { get; set; }
}
public interface IExtended {
bool IsExtended { get; set; }
}
[Table("Items")] // <-- my nemesis
public class ExtendedItem : Item, IExtended {
[Column("_Extended")]
public bool IsExtended { get; set; }
}
I set up the code-first context:
public class MyContext : DbContext {
public MyContext(string connectionString) : base(connectionString) {
// manually creating the tables, no migrations
Database.SetInitializer<EfQueueContext>(null);
}
public DbSet<Item> Items { get; set; }
}
- Without DataAnnotation
[Table]
I get exception "Invalid column name 'Discriminator'" -- okay, weird but makes sense - With
[NotMapped]
I get exception "The entity type ExtendedItem is not part of the model for the current context" -- okay, makes sense - With annotation
[Table("Item"]
I get exception "table 'dbo.Item' doesn't exist" -- okay, duh forgot it pluralized original - With annotation
[Table("Items")]
I get exception "table 'dbo.Items1' doesn't exist" -- what??? where did the1
suffix come from? Even creating a brand-new(update - I didn't actually create a clean instance; see comment on answer)DbContext
that only refers toExtendedItem
and notItem
still adds the '1'