© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
24 replies
𝐃𝐞𝐫𝐢𝐬𝐨𝐧

❔ [EF Core] Ignore properties from constructor of base class

Hey, I am currently trying to implement a new model in EF Core which looks like this:
internal class PlayerV : Player
{
    public bool LoggedIn { get; set; }

    public PlayerV(ICore Core, IntPtr NativePointer, ushort Id) : base(Core, NativePointer, Id)
    {
        LoggedIn = false;
    }
}
internal class PlayerV : Player
{
    public bool LoggedIn { get; set; }

    public PlayerV(ICore Core, IntPtr NativePointer, ushort Id) : base(Core, NativePointer, Id)
    {
        LoggedIn = false;
    }
}

In the current implementation, I only want to save the
LoggedIn
LoggedIn
property to the database, because I don't need the other ones from the base class. They're just needed for the business logic in the code. So I tried to ignore them with the
ModelBuilder
ModelBuilder
:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<PlayerV>()
        .Ignore(x => x.Core)
        .Ignore(x => x.NativePointer)
        .Ignore(x => x.Id);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<PlayerV>()
        .Ignore(x => x.Core)
        .Ignore(x => x.NativePointer)
        .Ignore(x => x.Id);
}

But I am still getting the error message:
No suitable constructor was found for entity type 'PlayerV'. The following constructors had parameters that could not be bound to properties of the entity type:
    Cannot bind 'Core', 'NativePointer', 'Id' in 'PlayerV(ICore Core, IntPtr NativePointer, ushort Id)'
Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound.
No suitable constructor was found for entity type 'PlayerV'. The following constructors had parameters that could not be bound to properties of the entity type:
    Cannot bind 'Core', 'NativePointer', 'Id' in 'PlayerV(ICore Core, IntPtr NativePointer, ushort Id)'
Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound.


That kinda makes sense to me. But I really need to find a way how just to ignore the properties from the base class, I don't want an additional database wrapper class or something. Is that possible?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Ef Core Constructor problem
C#CC# / help
4y ago
✅ EF Core navigational properties
C#CC# / help
3y ago
Calculated Properties with EF Core
C#CC# / help
2y ago
EF parameterless constructor
C#CC# / help
2y ago