C# 交叉应用LINQ-TO-SQL

C# 交叉应用LINQ-TO-SQL,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,有以下表格: create table Table_A ( Id int primary key identity, Status int not null ) create table Table_B ( Id int primary key identity, Value varchar(80) not null ) create table Table_C ( Id int primary key identity, Time datet

有以下表格:

create table Table_A (
    Id int primary key identity,
    Status int not null
)

create table Table_B (
    Id int primary key identity,
    Value varchar(80) not null
)

create table Table_C (
    Id int primary key identity,
    Time datetime not null
)
我想使用lambda表示法在LINQ to SQL中编写以下查询:

 select * from TABLE_A a
 cross apply (
    select top 1 c.Time from TABLE_B b
    inner join TABLE_C c on c.Id = b.Id
    where b.Id = a.Id
    order by c.Time asc
 ) d
 where a.Status = 10 and d.Time > '2021-03-09'

我该怎么做呢?

不确定LinqToSql如何翻译它,但是像
EF-Core
linq2db
这样的现代LINQ提供者应该将这个LINQ查询翻译成交叉应用

var date = new DateTime(2021, 03, 09);

var query =
    from a in db.TABLE_A
    from d in (
            from b in db.TABLE_B
            join c in db.TABLE_C on b.Id equals c.Id
            where b.Id = a.Id
            orderby c.Time
            select new { b, c }
        ).Taske(1)
    where a.Status == 10 && d.Time > date
    select new { a, d.b, d.c };

EF Core 5不再像这样翻译它了。它转换为ROW_NUMBER()(在LinqPad中运行良好(并产生交叉应用)的所有查询上的分区和超时。好吧,这是优化。在这种情况下可能是错误的。