none
How can I set one directional relation between two tables in EF Code First RRS feed

  • Question

  • For all classes in my Entity I have  a base class named CommonFields

    public class CommonFields
       
    {
           
    public int Status { get; set; }
           
    public DateTime CreatedOn { get; set; }
           
    public int CreaedBy { get; set; }
           
    public DateTime ModifiedOn { get; set; }
           
    public int ModifiedBy { get; set; }
       
    }

    And, for eg. I have two classes like

    public class Employee : CommonFields
       
    {
           
    public int Id { get; set; }
           
    public string Name { get; set; }
           
    //Other properties
       
    }

       
    public class User : CommonFields
       
    {
           
    public int Id { get; set; }
           
    public string Name { get; set; }
           
    //Other properties
       
    }

    How can I set relation from CreatedBy & ModifiedBy to User table. I just need only one directional mapping. Its a one to one relation and I don't want a FK column to be added for each table into my User table.

    I need to get User information when I write objEmployee.CreatedUser

    Thanks.

    Wednesday, May 1, 2013 3:04 AM

Answers