i have a question about EF4 and want to explain it by an example :
class User
{
public int Type;
public object Pointer;
}
class Admin
{
public Username;
public Password;
...
}
class Manager
{
public Username;
public Password;
...
}
class Member
{
public Username;
public Password;
...
}
I want to design this :
look at the User class , if User.Type == 1 I want to User.Pointer points to a object of Admin class and if User.Type == 2 I want to User.Pointer points to a object of Manager class and last , if User.Type == 3 i want to User.Pointer points to a object of Member class.
but i want to know it is possible to design this in EF4?How ? is there any solution to design something like that ? can I get some help of Map Details window in Visual Studio 2010 to do that? i need advice friends , l an waiting 🙂
regards , Ali
Yes this is possible in EF 4 but a little different then what you are trying to do now.
Instead of making separate classes for each user type and defining properties like UserName and Password on each of them, you can use inheritance.
If you create a base class
Userand defineUserNameandPasswordon them, you can inherit all the other user types fromUser.EF knows how to map this to a database and uses a discriminator column for it, just like you said, where a certain index points to a class type. The Mapping Details window, is indeed the window that can help you. Here you can specify what the discriminator column is and which row should point to which entity.
Here is some documentation that can help you further if you use an Entity Model, or here if you use the Code First approach.