linq 多表查询

 1            var v_Repair = from t_repair in context.T_RPRepair
 2                            join t_top in context.TopCombine on t_repair.RoadID equals t_top.unique_id
 3                            join t_user in context.T_wxUser on t_repair.openid equals t_user.openId
 4                            select new
 5                            {
 6                                guid = t_repair.Guid,
 7                                rpId = t_repair.RoadID,
 8                                oPhoto = t_repair.oldPhotoPath,
 9                                nPhoto = t_repair.newPhotoPath,
10                                status = t_repair.status,
11                                fixTime = t_repair.fixTime,
12                                fixContent = t_repair.fixContent,
13                                reportTime = t_repair.reportTime,
14                                name = t_top.biaozhunmingcheng,
15                                type = t_top.leibiemingcheng,
16                                openid = wxId,
17                                nickName = t_user.nickname
18                            };

老是忘记 备忘一下

时间: 2024-08-05 02:37:24

linq 多表查询的相关文章

Linq多表查询 返回组合实体 踩坑记

新年就不再记流水账了吧,无关紧要的日志太多也不好,有时要找自已记录的一些要点要翻半天 春节假期在家陆陆续续也有在做公司的事,主要是重构,接手的代码看着比较乱,花了很多时间来重构,现在看上去好多了. 使用Linq进行多表查询,要返回各个表的几个组合数据, public class A{ public string NameA{get; set;} } public class B{ public string NameB{get; set;} } 1.原先项目是定义了一个类,里面包含几张表的各个字

LINQ 联表查询 取count 值

linq to sql 实现左外部连接:var query=from a in A join b in B on a.ID equals b.aID into ab from a1 in ab.DefaultIfEmpty() select a1; 然后取query.Count()就行了   因为是延迟查询所以不会多查数据

linq多表查询

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Otsuka.Application.Dal; using Otsuka.Application.Bll.Common; using Otsuka.Application.Common; using Otsuka.Application.Bll.Dialog.ApplicationFind; namespace O

Linq 中 表连接查询

1 public void Test(){ 2 3 var query = from a in A join b in B on A.Id equals B.Id into c 4 from d in c.DefaultIfEmpty() 5 select d; 7 } Linq 中 表连接查询,布布扣,bubuko.com

Linq的连表查询

Linq做连表查询,可以先查出A.B表,然后再join A.B表,操作A.B组合的匿名表X var table1=from r in shiti.a() from y in r.years where y>2010 select new { year=y, name=r.FirstName }; var table2=from t in shiti.b() from y in t.years where y>2010 select new { year=y, name=t.name } 然后根

LINQ to DataSet 之单表查询

       查询单个数据表        根据Linq to DataSet概述的步骤, 第一步我们获取数据源,我们这里手动创建一个datatable数据源 static DataSet BuildOneDTDataSet() { string[] nameset = { "张三", "李思思", "lisi", "王五", "路六", "欧赔", "夏琪",&qu

.net Linq多表组合查询结果集

背景: 主流程表中包含员工ID及流程类型ID,在页面查看流程是需要显示员工姓名及流程名称 操作: //先进行分页处理原始数据 var result = from p in _dbContext.Set<BeWorkflowContent>() select p; if (searchWhere != null) result = result.Where(searchWhere); if (order != null) result = result.OrderByDescending(ord

使用Entity Framework Core需要注意的一个全表查询问题

.NET Core 迁移工作如火如荼,今天在使用 Entity Frameowork Core(又名EF Core)时写了下面这样的 LINQ 查询表达式: .Where(u => u.Id == new Guid(userId)).FirstOrDefaultAsync(); 结果在 SQL Server Profiler 中发现竟然进行了全表查询. 之后将 new Guid(userId) 从表达式中移出,保存于一个局部变量中,使用这个局部变量进行查询,全表查询问题就解决了. var use

sql 、linq、lambda 查询语句的区别

LINQ的书写格式如下: from 临时变量 in 集合对象或数据库对象 where 条件表达式 [order by条件] select 临时变量中被查询的值 [group by 条件] Lambda表达式的书写格式如下: (参数列表) => 表达式或者语句块 其中: 参数个数:可以有多个参数,一个参数,或者无参数. 参数类型:可以隐式或者显式定义. 表达式或者语句块:这部分就是我们平常写函数的实现部分(函数体). 1.查询全部 实例 Code 查询Student表的所有记录. select *