Common Table Expression in EntityFramework

后端 未结 5 1970
小蘑菇
小蘑菇 2020-12-19 05:34

I have this query in Sql Server which I need to consume in EntityFramework, So how can I write a EntityFramwork code which will have the same result as this

         


        
5条回答
  •  执笔经年
    2020-12-19 06:00

    Getting input from the other experts over SO, I have come up with my own way to achieve this.

    IEnumerable sg = dbContext.ExecuteStoreQuery(
                            @"WITH    q AS
                                        (
                                        SELECT  *
                                        FROM    LedgerGroups
                                        WHERE   GroupParent = 'Customers'
                                        UNION ALL
                                        SELECT  m.*
                                        FROM    LedgerGroups m
                                        JOIN    q
                                        ON      m.GroupParent = q.GroupName
                                        )
                                SELECT  *
                                FROM    q
                            ");
    

提交回复
热议问题