I am trying to figure out how best to define POCO classes in order to be able to use the first Entity Framework function.
I want to define some foreign key relationships in my classes, between the user, and also between the classes themselves. For example, consider the following 3 classes:
Public class Job { public int JobID {get; set;} public string JobTitle {get; set;} public virtual ICollection<Resume> Resumes {get; set;} // Is this correct at all? How to access all resumes for a certain job? (many-to-many relationship between Job and Employee) } Public class Resume { public int EmployeeID {get; set;} // or should it be: public virtual Employee EmployeePerson? public int JobID {get; set;} // or should it be: public virtual Job UserJob? public DateTime EmploymentDate {get; set;} } public class Employee { public int EmployeeID {get; set;} public int UserID{ger; set;} // or should it be: public virtual MembershipUser User? public ICollection<Resume> Resumes {get; set;} // Is this correct at all? }
The user is a membership user located in System.Web.Security
, which is authenticated using FormsAuthentication or ActiveDirectoryAuthentication. Questions are mentioned in the code (in the comments). But to clarify:
- Should I define objects in relationships and use
.Include
every time I need them, or is it better to store the identifier of objects and try to get data from this identifier every time I need? Should I use a different approach when working with the MembershipUser
class instead of my specific classes? - What other uses of
virtual
besides the possibility of lazy loading? Where should I avoid it and where to use it?
Thanks.
UPDATE . I just checked the definition of Employee with the definition of ublic virtual MembershipUser User
. The result was 4 added columns in my table:
- User_Email,
- User_Comment,
- User_IsApproved,
- User_LastLoginDate,
- User_LastActivityDate
Nothing unique to the user (User_Email is defined as NULL). So, if you want to have users in your classes, write a wrapper for MembershipUser
or just save the UserID.
Thank you, Ladislav and Sergi.
source share