-
-
Notifications
You must be signed in to change notification settings - Fork 621
Description
Is it possible to do a BulkInsert if using TPT?
https://docs.microsoft.com/en-us/ef/core/modeling/inheritance#table-per-type-configuration
I've tried but came up short. We have a base log-table and derived log-tables from that.
Example:
public abstract class Log
{
public int LogId { get; set; }
public int PersonId { get; set; }
public int RegBy { get; set; }
public DateTime CreatedDate { get; set; }
public virtual Person Person { get; set; }
}
public class LogPersonReport : Log
{
public int ReportId { get; set; }
public int LogPersonReportTypeId { get; set; }
public virtual Report Report { get; set; }
public virtual LogPersonReportType LogPersonReportType { get; set; }
}
modelBuilder.Entity<Log>().ToTable("Logs");
modelBuilder.Entity<LogPersonReport >().ToTable("LogPersonReports");
So with that class I'm able to write:
var logPersonReport = new LogPersonReport
{
PersonId = xx,
LogPersonReportTypeId = xx,
RegBy = xx,
CreatedDate = DateTime.Now
}
So, I want to do a BulkInsert with a list of LogPersonReports but I just get errors á la:
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT TOP 0 T.[LogId], T.[CreatedDate], T.[PersonId], T.[RegBy], T.[LogPersonReportTypeTypeId] INTO [dbo].[LogPersonReportsTempddc62ff7] FROM [dbo].[LogPersonReports] AS T LEFT JOIN [dbo].[LogPersonReports] AS Source ON 1 = 0;
Invalid column name 'CreatedDate'.
I understand why, because CreatedDate is a member of Log but I just don't know how to work around it? I've tried to first BulkInserted the base-entities which works but not when I set negative values for LogId and use SetOutputIdentity = true so that I can use LogId for LogPersonReport. When I use SetOutputIdentity I get errors like LogPersonReportTypeId is invalid even though I specify PropertiesToInclude.
So, I'm stuck and I'm not sure it's supported so I thought I should ask before I try more.