如下图所示关系型数据,LinQ语句为:
varQuery=fromaindata.Awherea.admin==传入的用户名&&a.pwd==传入的密码(可以传入一个model实体)join bindata.B
on a.bid equals b.id into abfromr1inab.DefaultIfEmpty()
join cindata.C
on r1.cid equals c.id into bcfromr2inbc.DefaultIfEmpty()
join dindata.D
on r2.did equals d.id into cdfromr3incd.DefaultIfEmpty()
selectnew{//这里是table A 的id;Id =a.Id,//这里是table B的Name;Name =r1.Name,PRo=r2.Pro,ipAdd=r3.IpAdd
};//转成数组形式;varlist =Query.ToList();//list[0].Name即表示整个LinQ查询的结果的第一条数据的table B的Name,以此类推;
注: r1可以.出table B的所有数据...以此类推;
r2==table C;
r3==table D;
=====================================================================================================
11、左连接:23varLeftJoin =fromempinListOfEmployees4join deptinListOfDepartment5on emp.DeptID equals dept.ID into JoinedEmpDept6fromdeptinJoinedEmpDept.DefaultIfEmpty()7selectnew8{9EmployeeName =emp.Name,10DepartmentName = dept !=null? dept.Name :null11};121314152、右连接:1617varRightJoin =fromdeptinListOfDepartment18join employeeinListOfEmployees19on dept.ID equals employee.DeptID into joinDeptEmp20fromemployeeinjoinDeptEmp.DefaultIfEmpty()21selectnew22{23EmployeeName = employee !=null? employee.Name :null,24DepartmentName =dept.Name25};262728293、内连接:3031varquery =fromtinentitiy.TB_GCGL_ADA_USER32join pinentitiy.TB_GCGL_ZY_ZYK33on t.ETPRS_CODE equals p.ETPRS_CODE3435selectnewTB_USER_ZYK36{37USER_ID =t.USER_ID,38USER_NAME =t.USER_NAME,39USER_PASSWord=t.USER_PASSWORD,4041};