如何在LINQ-to SQL中编写这个交叉应用查询?
发布时间:2020-12-12 16:31:26 所属栏目:MsSql教程 来源:网络整理
导读:我有以下表格: create table TableA ( Id int primary key identity,Key int not null)create table TableB ( Id int primary key identity,TableA_Id int not null foreign key references TableA(Id),Value varchar(80) not null) 我想使用lambda表示法在L
我有以下表格:
create table TableA ( Id int primary key identity,Key int not null ) create table TableB ( Id int primary key identity,TableA_Id int not null foreign key references TableA(Id),Value varchar(80) not null ) 我想使用lambda表示法在LINQ-to-SQL中编写以下查询: select TableA.Key,b.Value from TableA cross apply ( select top 10 TableB.Value from TableB where TableA.Id = TableB.TableA_Id order by TableB.Value ) b where TableA.Key between 0 and 999 我该怎么做? 解决方法这应该是诀窍var query = from a in context.TableA from b in context.TableB .Where(x => x.TableA_Id == a.Id) .OrderBy(x => x.Value) .Take(10) where a.Key >= 0 && a.Key <= 999 select new { a.Key,b.Value,}; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- SQLServer删除/重建/禁用/启用外键约束
- MySQL对limit查询语句的优化方法
- mapping – 具有多个joinColumns的Doctrine 2 ManyToOne
- SQLSERVER和ORACLE批量处理表名和字段名大写
- SQL Server 多列复合索引的使用 绕过微软sql server的一个缺
- 公布下SQL Server 2008 RC0英文版下载地址
- sql – 不允许保存更改 您所做的更改需要删除以下表格并重新
- sql – 将Varchar转换为NVarchar?
- sql – 如何查询存储在数组中的Rails ActiveRecord数据
- sql – 操作数类型冲突:uniqueidentifier与int不兼容