Your problem here is what @millimoose said: EF can only return emUser
objects, because it doesn't know about User
and an emUser
might not be a User
.
You have three possible solutions from here:
- Set up
User
to inherit fromEntityObject
, then haveemUser
inherit fromUser
. This would be a pain to implement and not give you any useful advantages. - Create Data Transfer Objects to pass around, where you basically copy all the properties from an
emUser
into aUser
(usually via theUser
's constructor). This would give you the separation you want, but would be a pain. - Add the extra properties into a new
partial
class foremUser
. This is the one I highly recommend, because it's simple and straightforward.
Here's an example:
// In a manually generated file in the same project
public partial class emUser
{
#region Properties
public string Username
{
get { return Email; }
}
public string FullName
{
get { return FirstName + " " + LastName; }
}
#endregion
}
// In the automatically generated file
public partial class emUser : EntityObject
{
[code ...]
}
Usage:
emUser foo = GetUser();
Console.WriteLine("FirstName: " + emUser.FirstName);
Console.WriteLine("FullName: " + emUser.FullName);