如何使用多个外键创建实体框架

时间:2014-12-07 12:18:29

标签: c# linq entity-framework

我有一个支持多种语言的ASP.NET MVC项目。

表(User,Gender,GenderTranslate)具有嵌套继承 用户从性别和性别继承继承自GenderTranslate

我有这些表

User表:

    public partial class User
    {
           public int Id { get; set; }
           public string Name { get; set; }
           public Nullable<int> GenderID { get; set; }

           public virtual Gender Gender { get; set; }
    }

Gender表:

    public partial class Gender
    {
         public Gender()
         {
             this.GenderTranslates = new HashSet<GenderTranslate>();
             this.Users = new HashSet<User>();
         }

         public int Id { get; set; }
         public string Icon { get; set; }
         public string Value { get; set; }

         public virtual ICollection<GenderTranslate> GenderTranslates { get; set; }
         public virtual ICollection<User> Users { get; set; }
    }

Language表:

    public partial class Lang
    {
        public Lang()
        {
            this.GenderTranslates = new HashSet<GenderTranslate>();
        }

        public int Id { get; set; }
        public string Name { get; set; }

        public virtual ICollection<GenderTranslate> GenderTranslates { get; set; }
    }

GenderTranslate表:

    public partial class GenderTranslate
    {
        public int LangID { get; set; }
        public int GenderID { get; set; }
        public string Desc { get; set; }

        public virtual Gender Gender { get; set; }
        public virtual Lang Lang { get; set; }
    }

当我收到用户时,我需要GenderTranslate.Desc,而不是Gender.Value

如何使用Entity Framework执行此操作?请帮帮我

0 个答案:

没有答案