Allow queries for mapped abstract base class with no discriminator
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the EF Core 5.0 model configuration and DbContext usage shown in the issue, then reproduce both SaveChanges and CountAsync with the supplied SQL Server setup. Done means determining the expected behavior for a mapped abstract base class without a discriminator and documenting or testing the confirmed failure.
Written by the indexing model from the issue text.
Description
Hi,
I am experiencing an issue while building model using EF Core (EF Core 5.0).
Console application (NET5) fails when trying to SaveChanges: "AMOS_ADDRESS is not mapped to a Table"
as reported in the attached screenshot.
Please can you help me in understanding what I am doing wrong?
Thanks
var loggerFactory = LoggerFactory.Create(builder => {
builder.AddFilter("Microsoft", LogLevel.Debug)
.AddFilter("System", LogLevel.Debug)
.AddFilter("ConsoleApp4.Program", LogLevel.Debug)
.AddConsole();
});
var optionBuilder = new DbContextOptionsBuilder();
optionBuilder.UseLazyLoadingProxies(true);
optionBuilder.UseLoggerFactory(loggerFactory);
var modelBuilder = new ModelBuilder();
modelBuilder.HasDefaultSchema("AMOS");
modelBuilder.Entity<AMOS_ADDRESS>(b => b.ToTable("ADDRESS"));
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.CODE).HasColumnName("CODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ALPHACODE).HasColumnName("ALPHACODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<AMOS_ADDRESS>().HasKey(e => e.ADDRESSID);
modelBuilder.FinalizeModel();
optionBuilder.UseModel(modelBuilder.Model);
//optionBuilder.UseInMemoryDatabase(databaseName: "myDb");
var connection = Microsoft.Data.SqlClient.SqlClientFactory.Instance.CreateConnection();
connection.ConnectionString = "Data source=localhost;Initial catalog=ABS10.0.30;User ID=amos;Password=voyager";
connection.Open(); // Works
// To prove that table exists and connection works
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(1) from AMOS.ADDRESS";
var count = (int)command.ExecuteScalar();
Console.WriteLine($"Address count {count}");
}
optionBuilder.UseSqlServer(connection);
var dbContext = new myDbContext(optionBuilder.Options);
dbContext.Addresses.Add(new AMOS_ADDRESS() { CODE = "001", ADDRESSID = 1, ALPHACODE = "A001" });
dbContext.Addresses.Add(new AMOS_ADDRESS() { CODE = "002", ADDRESSID = 2, ALPHACODE = "A002" });
dbContext.Addresses.Add(new AMOS_ADDRESS() { CODE = "003", ADDRESSID = 3, ALPHACODE = "A003" });
dbContext.Addresses.Add(new AMOS_ADDRESS() { CODE = "004", ADDRESSID = 4, ALPHACODE = "A004" });
dbContext.SaveChanges(); // FAILS AMOS_ADDRESS is not mapped to a table
var addresses = dbContext.Addresses;
Console.WriteLine(addresses.CountAsync().Result); // Fails AMOS_ADDRESS is not mapped to a table

- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100