-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping exception with property called FooId on base type Foo in TPT #23092
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
@AndriySvyryd This feels like something we should patch. I haven't been able to come up with any workarounds; could you take a look? Some repo code: [Table("Foo")]
public abstract class Foo
{
[Key]
public int Id { get; set; }
public int? FooId { get; set; }
}
[Table("Car")]
public partial class Car : Foo
{
[StringLength(15)]
public string Registry { get; set; }
}
public class Program
{
public static void Main()
{
using var context = new BlogContext();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
}
public class BlogContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Car> Cars { get; set; }
static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.EnableSensitiveDataLogging()
.UseLoggerFactory(ContextLoggerFactory);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
} |
A workaround would be to configure the implicit relationship to the base type explicitly while the property is ignored: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Object>().Ignore(e => e.ObjectId);
modelBuilder.Entity<Car>().HasOne<Object>().WithOne()
.HasForeignKey<Car>(c => c.Id);
modelBuilder.Entity<Object>().Property(e => e.ObjectId);
} There are actually two bugs that together make this manifest:
|
AndriySvyryd
added a commit
that referenced
this issue
Oct 28, 2020
Silently ignore inherited properties in TPT in SqlServerIndexConvention Fixes #23092
AndriySvyryd
added a commit
that referenced
this issue
Oct 28, 2020
AndriySvyryd
added a commit
that referenced
this issue
Oct 29, 2020
Silently ignore inherited properties in TPT in SqlServerIndexConvention Fixes #23092
AndriySvyryd
added a commit
that referenced
this issue
Oct 29, 2020
AndriySvyryd
added a commit
that referenced
this issue
Nov 12, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
File a bug
Fails to map property in Table-per-Type inheritance (SQL Server provider)
I think it is about the conventions. The type being named
Object
and assuming ``ObjectId```is a primary key that should be in the derived types table.When I remove
ObjectId
everything works just fine.I explored potential workarounds but not even renaming the column in the database an adding
Column
handles the problem. It still complains about not being able to map the propertyObjectId
to Car.Code
Stack traces
Provider and version information
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0 RC2
Operating system:
IDE: Visual Studio 2019 16.3
The text was updated successfully, but these errors were encountered: