@Pk1425 , Welcome to Microsoft Q&A, you could try the following code to write a generic class to get what you wanted.
public class Model1
{
public int Id;
public int Dx;
public int Cy;
public string Key1;
public string Key2;
}
public class Example<T> where T : Model1
{
public Task<T> Save(T t)
{
//need to set key before saving the model
t.Key1 = $"m1.Id-Dx"; // I want it to be set here only not by the caller
t.Key2 = $"m1.Id-Cy";
//Save to Db
return Task.FromResult(t);
}
// Likewise I have few other methods like Delete etc
}
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.