我有以下表格:
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
)
Run Code Online (Sandbox Code Playgroud)
我想使用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
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
Adu*_*cci 30
这应该可以解决问题
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,
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10055 次 |
最近记录: |