With TPT i want to duplicate the ChangedDate information also in the Table2 Employee (its possible that just that table gets changed later..)
How is it possible to "force" EF Core that the Field "Createddate" is in the Base table AND in the inherited table? by specifying it in the configation its not working. The insert always failes in the Employee table because EF Core does not specify the not nullable ChangedDate Column in the insert query. The insert on Person Table works.
SQL Schema
CREATE TABLE [dbo].[tbl_Person](
[PersonId] [bigint] IDENTITY(1,1) NOT NULL,
[Name1] [nvarchar](35) NOT NULL,
[ChangedDate] datetime NOT NULL
)`
CREATE TABLE [dbo].[tbl_Employee](
[PersonId] [bigint] NOT NULL,
[ChangedDate] datetime NOT NULL
)
EF Model
public abstract class TblPerson
{
public long PersonId { get; set; }
public string Name1 { get; set; }
public DateTime ChangedDate{ get; set; }
}
public class TblEmployee : TblPerson
{
public DateTime ChangedDate{ get; set; }
}
EF Configuration
public class TblEmployeeConfiguration : IEntityTypeConfiguration<TblEmployee >
{
public void Configure(EntityTypeBuilder<TblEmployee > builder)
{
builder.ToTable("tbl_Employee", "dbo");
builder.HasBaseType<TblEmployee >();
builder.Property(x => x.PersonId).HasColumnName(@"PersonId").HasColumnType("bigint").IsRequired().ValueGeneratedOnAdd().Us eIdentityColumn();
builder.Property(x => x.ChangedDate).HasColumnName(@"ChangedDate").HasColumnType("datetime").IsRequired();
}
public class TblPerson : IEntityTypeConfiguration<TblPerson>
{
public void Configure(EntityTypeBuilder<TblPerson> builder)
{
builder.ToTable("tbl_Person", "dbo");
builder.HasBaseType<TblPerson>();
builder.Property(x => x.PersonId).HasColumnName(@"PersonId").HasColumnType("bigint").IsRequired().ValueGeneratedOnAdd().Us eIdentityColumn();
builder.Property(x => x.ChangedDate).HasColumnName(@"ChangedDate").HasColumnType("datetime").IsRequired();
}
Wrong Query generated
exec sp_executesql N'SET NOCOUNT ON;
INSERT INTO [dbo].[tbl_Person] ([PersonId])
VALUES (@p24);
',N'@p24 bigint',@p24=6000196
Expected Query to be generated
exec sp_executesql N'SET NOCOUNT ON;
INSERT INTO [dbo].[tbl_Person] ([PersonId], [ChangedDate])
VALUES (@p24, @p25);
',N'@p24 bigint,@p25 datetime',@p24=6000196,@p25='2022-11-15 10:40:31.953