LINQ查询,用于使用实体框架从具有Lambda表达式且没有Join关键字的多个表中获取数据

LINQ查询,用于使用实体框架从具有Lambda表达式且没有Join关键字的多个表中获取数据,linq,sql-server-2008,asp.net-web-api,lambda,entity-framework-6,Linq,Sql Server 2008,Asp.net Web Api,Lambda,Entity Framework 6,我想根据employeeNumber从三个表中获取员工的详细信息 三张表: EmployeeDetails(employeeNumber primarykey和userID,名称ID Foreignkey) 用户详细信息(用户ID primaryKey) 名称(名称ID主键) 用户详细信息 public partial class UserDetail { public UserDetail() { this.Employe

我想根据employeeNumber从三个表中获取员工的详细信息

三张表:

  • EmployeeDetails(employeeNumber primarykey和userID,名称ID Foreignkey)
  • 用户详细信息(用户ID primaryKey)
  • 名称(名称ID主键)
  • 用户详细信息

        public partial class UserDetail
        {
            public UserDetail()
            {
                this.EmployeeDetails = new HashSet<EmployeeDetail>();
            }
            public System.Guid user_id { get; set; }
            public string employee_name { get; set; }
            public string employee_email { get; set; }
            public decimal employee_contactnumber { get; set; }
    
    
        public virtual ICollection<EmployeeDetail> EmployeeDetails { get; set; }
    }
    
    public partial class EmployeeDetail
        {       
            public System.Guid employee_id { get; set; }
            public Nullable<System.Guid> user_id { get; set; }
            public int employee_number { get; set; }          
            public Nullable<int> designation_id { get; set; }           
    
            public virtual Designation Designation { get; set; }         
            public virtual UserDetail UserDetail { get; set; }
        }
    
    公共部分类UserDetail
    {
    公共用户详细信息()
    {
    this.EmployeeDetails=newhashset();
    }
    public System.Guid用户\u id{get;set;}
    公共字符串employee_name{get;set;}
    公共字符串employee_email{get;set;}
    公共十进制雇员\u联系人号码{get;set;}
    公共虚拟ICollection EmployeeDetails{get;set;}
    }
    
    员工详细信息

        public partial class UserDetail
        {
            public UserDetail()
            {
                this.EmployeeDetails = new HashSet<EmployeeDetail>();
            }
            public System.Guid user_id { get; set; }
            public string employee_name { get; set; }
            public string employee_email { get; set; }
            public decimal employee_contactnumber { get; set; }
    
    
        public virtual ICollection<EmployeeDetail> EmployeeDetails { get; set; }
    }
    
    public partial class EmployeeDetail
        {       
            public System.Guid employee_id { get; set; }
            public Nullable<System.Guid> user_id { get; set; }
            public int employee_number { get; set; }          
            public Nullable<int> designation_id { get; set; }           
    
            public virtual Designation Designation { get; set; }         
            public virtual UserDetail UserDetail { get; set; }
        }
    
    公共部分类EmployeeDetail
    {       
    public System.Guid employee_id{get;set;}
    公共可为空的用户\u id{get;set;}
    公共整数雇员_编号{get;set;}
    公共可为空的指定\u id{get;set;}
    公共虚拟指定{get;set;}
    公共虚拟用户详细信息用户详细信息{get;set;}
    }
    
    名称

     public partial class Designation
        {
            public Designation()
            {
                this.EmployeeDetails = new HashSet<EmployeeDetail>();
            }
    
            public int designation_id { get; set; }
            public string designation_name { get; set; }
            public Nullable<System.DateTime> create_date { get; set; }
    
            public virtual ICollection<EmployeeDetail> EmployeeDetails { get; set; }
        }
    
    公共部分类名称
    {
    公众指定()
    {
    this.EmployeeDetails=newhashset();
    }
    公共整数指定_id{get;set;}
    公共字符串名称\u name{get;set;}
    公共可空的create_date{get;set;}
    公共虚拟ICollection EmployeeDetails{get;set;}
    }
    
    如果您还没有将导航属性添加到实体类中,我建议您添加导航属性。这将导致EF注入联接,而无需指定联接条件

    更改标识符以匹配约定,否则必须显式配置关联

    public class Employee
    {
        public int EmployeeId { get; set; }
    
        public int UserDetailId { get; set; }
        public UserDetail UserDetail { get; set; }
    }
    
    public class UserDetail
    {
        public int UserDetailId { get; set; }
        public string SomeUserDetailProperty{ get; set; }
    
        public ICollection<Employee> Employees { get; set; }
    }
    
    这很好用。多谢各位

    GetUserInfo类包括:

       public class GetUserInfo{
    
         public UserDetails userDetail {get;set;}
         public EmployeeDetails employeeDetail {get;set}
         public Designations designation{get;set;}
    }
    

    在数据库中创建一个视图,并在entityframework中使用该视图获取数据

    e.UserDetail.SomeUserDetailProperty,在e.UserDetails之后。当然,
    SomeUserDetailProperty
    是您可能希望从
    UserDetail
    中选择的示例。你能编辑你的问题来包括你的实体类吗?我的意思是,除了我的表之外,它还显示Add、Array、select等。好的,我会编辑