0

i am having a problem affecting my json values into their corresponding properties due to inheritence.

in short i have this architecture :

public class a 
{
  public Guid PKey { get; set; }
}

public class b : a 
{
 public string UserCreate { get; set; }
 public string UserCreateDateTime { get; set; }
}

public class c : b 
{
 //many properties
}

i used to have the properties from class a & b in their respective classes (c) which was no problem so all of my APIs are like this

{
      "Tier": {
        "PKey":"00000000-0000-0000-0000-000000000000",
        "usercreate":"name",
      },
      "Prospection":{
        "pkey":"00000000-0000-0000-0000-000000000000",
      },
      "category":{
        "Id": "00000000-0000-0000-0000-000000000000"
      },
      "type":{
        "Id": "00000000-0000-0000-0000-000000000000"
      }
}

basically when my controller recieves the JSON file it cannot/won't affect the 'pkey' and the properties from class b into their respective properties of the base classes. i have came to a conclusion that i should make a function to manually affect the values with type handling but i feel like it's the wrong approach seeing as how all my entities have the same problem if i am to apply this architectural change.

i am working on .NET5.0 and Entity Framework Core.

EDIT

i have found a solution

json.net does not serialize properties from derived class

0 Answers0