2017-09-01 113 views

回答

2

EF核2.0沒有實現GROUP BY。

您可以使用FromSql到execute a raw SQL query並將其映射到一個實體,或者你可以創建一個視圖並將其映射到一個實體,就好像它是一個表,如:

class BlogPostCount 
{ 
    public int BlogID{get;set;} 
    public int Count {get;set;}   
} 


var query = "SELECT BlogID,Count(*) as Count from BlogPosts group by BlogID"; 
var counts = context.BlogPostCounts.FromSQL(query).ToList();