Git Product home page Git Product logo

Comments (10)

borisdj avatar borisdj commented on August 16, 2024

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.

Alexx999 avatar Alexx999 commented on August 16, 2024

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.

borisdj avatar borisdj commented on August 16, 2024

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.

Alexx999 avatar Alexx999 commented on August 16, 2024

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.

borisdj avatar borisdj commented on August 16, 2024

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.

Alexx999 avatar Alexx999 commented on August 16, 2024

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.

borisdj avatar borisdj commented on August 16, 2024

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.

borisdj avatar borisdj commented on August 16, 2024

New nugget just published.

from efcore.bulkextensions.

Alexx999 avatar Alexx999 commented on August 16, 2024

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.

borisdj avatar borisdj commented on August 16, 2024

No rush, if something comes up it can always be fixed with another nugget version.

from efcore.bulkextensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.