Comments (10)
You can bypass this problem by making custom Discriminator, which you probably have do to anyway in order to set value of Discriminator column, so you need real Discriminator property.
Example:
public abstract class Person
{
public int Id { get; set; }
public string Discriminator { get; protected set; }
...
}
public class Instructor : Person
{
public Instructor()
{
Discriminator = nameof(Instructor);
}
...
}
public class Student : Person
{
public Student()
{
Discriminator = nameof(Student);
}
...
}
And in DbContext.cx
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>().HasDiscriminator<string>("Discriminator")
.HasValue<Instructor>(nameof(Instructor))
.HasValue<Student>(nameof(Student));
}
from efcore.bulkextensions.
Well, problem is that I don't need to set any values there - EF Core is quite happily doing that for me and saving that into DB. However, it's impossible to save such entities with BulkExtension as there's no shadow property support.
PS: Now I see what you mean - I replied to PR thread.
from efcore.bulkextensions.
Configuration from the example above Does work with BulkExtension since here Discriminator is real property and not shadow, so there is no issue with FastMember either.
Table-Per-Hierarchy inheritance model can be set in 2 ways.
One is when EF does it automatically by Convention in which case you have shadow Property.
And second is like in this example where you explicitly define Discriminator property in Entity and configure it with .HasDiscriminator() but is not shadow.
Only if you exclusively want the first way and BulkOps then fix is required.
from efcore.bulkextensions.
I wonder if there are more cases where EF Core uses shadow properties. At least they can be freely added by a user so having some support for them (at least throwing NotSupportedException to let user know that they're not supported) is clearly required.
Because now it requires some debugging to figure out why the hell objects are not saving which isn't cool.
from efcore.bulkextensions.
I agree that Shadow support is good and will integrate it, just to figure the cleanest way.
Comment was to add info that TPH can be done with explicit config so without Shadow properties.
from efcore.bulkextensions.
Yeah, probably my initial message isn't very clear - I know that you can do that explicitly, however, by default EF Core will do that implicitly if your PK configuration allows.
from efcore.bulkextensions.
I have integrated Discriminator support, cleaned up code a little bit, removed some lines that were not being used and optimized it by checking first if Table has Shadow field.
I have also added test for this and it is passing.
So check the latest source and if all works for the situation you have I will publish the new version of nugget.
from efcore.bulkextensions.
New nugget just published.
from efcore.bulkextensions.
Sorry for late reply - test runs are quite long for me as DB size is over 100GB :)
So far it works fine - I guess it's okay.
from efcore.bulkextensions.
No rush, if something comes up it can always be fixed with another nugget version.
from efcore.bulkextensions.
Related Issues (20)
- BulkInsertOrUpdateAsync performance questions HOT 3
- Using EF Core 8 Complex Property results in error "Sequence contains no matching element"
- When using PostgreSQL to batch insert DateTime.Now data, there might be a time offset.
- BulkExtensions determines target DbContext incorrectly when calls to different database servers in parallel HOT 1
- VULN: CVE-2024-32655 in Npgsql dependency HOT 3
- BulkInsertOrUpdate doesn't return Identity when no insert or update happen
- not present in the dictionary.
- can BulkInsert support my custom ValueGenerator for Id column HOT 1
- BulkSaveChangesAsync leaves tracked entities in state of "Added" even after successful save. HOT 2
- Spatial support in SQLite for Point
- BulkRead: System.NotSupportedException: 'Specified method is not supported.'
- BulkInsert produces sytanx error on PostgreSQL (version 6.x) HOT 1
- Bulk operation fails when owned type has enum member on PostgreSQL
- `SharedTypeEntity` don't work with bulk operations HOT 1
- [MySql/MariaDb] Insert an boolean type has invalid result (Always insert true in a bit column) HOT 2
- Question : Set value on shadow properties "on save" HOT 1
- Unable to cast object of type 'System.Int64' to type 'System.Nullable`1[System.Int32]' HOT 1
- PostgreSQL Table-Per-Hierarchy Inheritance Is Not Working HOT 1
- Truncate method with custom table name HOT 1
- BulkInsertAsync is assigning negative values to inserted entries' primary keys HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.bulkextensions.