-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
Owned types in separate table does not work #114
Comments
Yes, currently are supported only 'Owned' types mapped by convention to the same table as the owner. |
Owned types that have seperate tables currently causes the
Can the library at least ignore the owned type property so that we can do the bulk update as a 2nd call (similar to how it would work if it wasn't an owned type)? |
Today, I encountered the same problem. I tried to set BulkConfig.PropertiesToExclude, but this doesn't change anything. I reviewed the code for EF Core 2.2, and can see that PropertiesToExclude/PropertiesToInclude are not applied to Owned Types. Would help, if at least we can ignore such owned properties by setting PropertiesToExclude/PropertiesToInclude. |
Also hitting this problem here. |
The same problem happens if OwnsMany is used but in this case, we cannot use @borisdj's approach as we cannot map them in the same table as the relation is 1-to-many. |
This can now, v3.4.6+, be achieved with 2 calls and config for mutual excluding Properties from other table. modelBuilder.Entity<ChangeLog>().OwnsOne(p => p.Audit, a => { a.ToTable(nameof(Audit)); }); public class ChangeLog
{
public int ChangeLogId { get; set; }
public string Description { get; set; }
public Audit Audit { get; set; }
}
[Owned]
public class Audit
{
public string ChangedBy { get; set; }
public bool IsDeleted { get; set; }
public InfoType InfoType { get; set; } // InfoType is Enum
} var entities = new List<ChangeLog>();
for (int i = 1; i <= 1000; i++)
{
entities.Add(new ChangeLog
{
Description = "Dsc " + i,
Audit = new Audit
{
ChangedBy = "User" + 1
InfoType = InfoType.InfoTypeA
}
});
var bulkConfig = new BulkConfig
{
SetOutputIdentity = true, // required to load Id that are need for second Bulk call into owned table
PropertiesToExclude = new List<string> {
$"{nameof(Audit)}.{nameof(Audit.ChangedBy)}",
$"{nameof(Audit)}.{nameof(Audit.IsDeleted)}",
$"{nameof(Audit)}.{nameof(Audit.InfoType)}",
}
};
var bulkConfigOwned = new BulkConfig
{
CustomDestinationTableName = nameof(Audit), // set name of Owned table as Destination
PropertiesToExclude = new List<string> { nameof(ChangeLog.Description) },
};
using (var transaction = context.Database.BeginTransaction())
{
context.BulkInsert(entities, bulkConfig);
context.BulkInsert(entities, bulkConfigOwned);
transaction.Commit();
} |
What about One-To-Many relationships? I am getting the Object reference not set to an instance of an object exception using an adapted version of your example above. |
I see that 'Owned' types is listed as supported but perhaps only with table splitting? When I use an owned type that is in a separate table it doesn't appear to be working. Here is the code to configure the owned entity:
The text was updated successfully, but these errors were encountered: