Reputation: 287
Can I call / use more than one table in my class?
e.g.
public class UserModel : UsersTable
How can I call another table in this class, e.g. CustomerTable, something like this:
public class UserModel : UsersTable : CustomerTable
Upvotes: 1
Views: 60
Reputation: 107247
If you want to re-use entity layer classes (e.g. Entity Framework objects) in your MVC ViewModels, I would use Composition, and not inheritance to achieve this, viz:
public class UserModel // View Model
{
public UsersTable UsersTable // EF POCO
{
get;
set;
}
public CustomerTable CustomerTable
{
get;
set;
}
// Other random data needed for your `.cshtml` / View
}
This way, you can extend your view model indefintely. As you've no doubt found, C# doesn't support multiple inheritance (or mixins / traits), so your options will be limited by inheritance (and it is arguably not logical, since a ViewModel
isn't a DTO
in the OO sense.)
Upvotes: 2