C
C#2y ago
adnan307

❔ Ef Core Constructor problem

Hello its my first big project with ef. I have an class with 3 attributes and one constructor that is calling the base constructor. My Class inherit from another class.
public class SPlayer : Player
{
public new int Id { get; set; }
public Account Account { get; set; }
public string Name { get; set; }

public SPlayer(ICore core, IntPtr nativePointer, ushort id) : base(core, nativePointer, id)
{

}
}
public class SPlayer : Player
{
public new int Id { get; set; }
public Account Account { get; set; }
public string Name { get; set; }

public SPlayer(ICore core, IntPtr nativePointer, ushort id) : base(core, nativePointer, id)
{

}
}
The problem is that ef core need an parameter less constructor. I tried to add an private constructor but its not working.
No suitable constructor was found for entity type 'SPlayer'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'core', 'nativePointer', 'id' in 'SPlayer(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 'SPlayer'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'core', 'nativePointer', 'id' in 'SPlayer(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.
8 Replies
Angius
Angius2y ago
Add a public parameterless constructor Or better yet, just remove the constructors you have and use required properties instead
adnan307
adnan307OP2y ago
the problem is that i need the constructor because the class i inherit from is a nuget
adnan307
adnan307OP2y ago
public constructor
adnan307
adnan307OP2y ago
this means that it tries to call the constructor but i dont have parameters
Angius
Angius2y ago
Remove ctor from that class as well Or just add a public parameterless ctor, that should work as well
adnan307
adnan307OP2y ago
the class i inherit from(nuget paket) is inheriting from another class... it wont work i need the constructor the picture above show an error when i add public parameterless ctor
Angius
Angius2y ago
One thing that comes to mind, is creating your own class that mirrors what the class from the nuget contains, use that class with EF, and just map between them as needed
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server