Subquery with Entity Framework

前端 未结 2 1186
野性不改
野性不改 2021-01-17 11:38

I\'m porting a subsystem from NHibernate to Entity Framework and want to see the best way to port the following query to EF.

var d         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 11:57

    The following query do exactly what I need with just one query to the database:

    var accountBalance = context
        .AccountBalanceByDate
        .Where(a => 
            a.Date == context.AccountBalanceByDate
                 .Where(b => b.AccountId == a.AccountId && b.Date < date).Max(b => b.Date));
    

    Thanks @AgentShark for the help.

    The code is on GIST: https://gist.github.com/sergiogarciadev/9f7bd31a21363ee0b646

提交回复
热议问题