𝐃𝐞𝐫𝐢𝐬𝐨𝐧
𝐃𝐞𝐫𝐢𝐬𝐨𝐧
CC#
Created by 𝐃𝐞𝐫𝐢𝐬𝐨𝐧 on 6/16/2023 in #help
❔ [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 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:
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?
25 replies