How to create an instance of an EF Core TPT type, When I have the property names of the TPT type as string values

39 Views Asked by At

I have a TPT hierarchy like this:

public class Product
{
}

public class Cat_Shirt : Product 
{
   string properties
}

public class Cat_Hat : Product 
{
   string properties
}

I can obtain all properties of a TPT entity (Cat_Shirt) like this (I have: TitleTPT="Cat_Hat" or "Cat_Shirt"):

var columnNames = context.Model.FindEntityType(
    Type.GetType(TitleTPT)).GetProperties().Select(x => x.GetColumnName()).ToList();

Now, I want to create a new instance of a TPTTitle ("Cat_Hat" or "Cat_Shirt") and possibly some product known properties set to a custom default value, how to do this?

And the second question is how to bind these object's properties in blazor? (how to use the created object)?

0

There are 0 best solutions below