I have a base class I would like to extend in order to add and/or modify some of the existing properties for it to be serialized to an SQL database.
Particularly, I have a non-trivial property that I would like to serialize as string:
public class BaseClass {
public NonTrivialType Id {get;set;}
}
Therefore, I was thinking of re-declaring in this derived class a new property with the same name:
public class DerivedClass : BaseClass {
public new string Id {get;set;}
}
This way, EntityFramework would pick that up, serialize it and use it as key using the following configuration in my DbContext's OnModelCreating
function:
modelBuilder.Entity<DerivedClass>().ToTable("MyTable").HasKey(_ => _.Id)
However, I get a validation exception, which means that EF is not doing what I wanted him to do.
My intention here is to "hide" the original declaration and only show/serialize the new one. Is that even possible?