Hi to you,
First, let`s make your question a little bit more clear and make sure that I understood right. So you have a class called
User
and a class called
Customer
which is a child class of the
User
class.
public class User
{
public string Id {get;set;}
public string Username {get;set;}
public SecureString Password {get;set;}
}
public class Customer : User
{
public Customer(User user)
{
Id = user.Id;
Username = user.Username;
Password = user.Password;
}
public string Name {get;set;}
}
var user = new User() { Id = "id", Username = "user" };
var customer = new Customer(user);
Ok, now where ever you want to create a customer from a user you just need to use the customer`s constructor and inject your user inside the customer object. However, I would prefer to have the user as a property of customer rather a child class of it. This will decouple these two entities and also will bring more flexibility and a clear understanding from the business point of view.
You can keep customers in a table with a foreign key to the user's table because a customer may have more than one user (depends strongly on your business model).
But, if for any reasonable reason you needed to use inheritance then what you can do is to create a base/abstract class like
Person
and drive both from this class.
Btw, you may also need to have a look at the Entity State Diagram which talks about different stats for the same Entity in different levels of the system.
Cheers,
AH