·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> Linq和EF做单一条件查询和复合条件查询以及多表联合查询示例
单一条件查询:
var table2Object = (from t1 in db.table1 join t2 in db.table2 on t1.id equals t2.id select t2).FirstOrDefault();
复合条件 查询:
多个主键 联合查询
var table2Object = (from t1 in db.table1 join t2 in db.table2 on new { t1.id, t1.another_id } equals new { t2.id, t2.another_id } select t2).FirstOrDefault();
多表联合查询:
Join3个Table
var table2Object = (from t1 in db.table1 join t2 in db.table2 on new { t1.id, t1.another_id } equals new { t2.id, t2.another_id } join t3 in db.table3 on new { t2.id, t2.another_id } equals new { t3.id, t3.another_id } select t2).FirstOrDefault();