Home > Blockchain >  C#, How to update common fields in models by using interface
C#, How to update common fields in models by using interface

Time:08-11

I have common field in all tables

public Guid UserId { get; set; }

How can I fill in this field without repeating the code?

I want to do it using the interface.

CodePudding user response:

It would be better to create base class and inherit from it in each model class.

public class BaseModel
{
    public Guid UserId { get; set; }
}

public class Table : BaseModel
{

}

If you use an interface, you will still need to implement the property in every class.

  • Related