Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将SQL Server查询转换为实体框架查询_Sql_Sql Server_Entity Framework_Linq - Fatal编程技术网

将SQL Server查询转换为实体框架查询

将SQL Server查询转换为实体框架查询,sql,sql-server,entity-framework,linq,Sql,Sql Server,Entity Framework,Linq,我有一个SQL Server查询,如下所示: select month(fact_date) as month, sum(case when beef_dairy_stat = 1 and param_id = 1 then 1 else 0 end) as cnt from user_behave_fact where YEAR(fact_date) = 2018 group by month(fact_date) order by m

我有一个SQL Server查询,如下所示:

select 
    month(fact_date) as month,
    sum(case when beef_dairy_stat = 1 and param_id = 1 then 1 else 0 end) as cnt
from 
    user_behave_fact
where 
    YEAR(fact_date) = 2018
group by 
    month(fact_date)
order by 
    month
由于

month   cnt
------------
  1     10
  2     20
现在,我需要将此查询转换为相应的实体框架查询

这是我目前的尝试:

var sql_rez_ICC = new List<Tuple<int, int>>();

sql_rez_ICC = db.user_behave_fact
                    .Where(x => x.fact_date.Value.Year == selected_year)
                    .GroupBy(y => y.fact_date.Value.Month)
                    .Select(y =>new { month = y.Select(x=>x.fact_date.Value.Month), icc_count = y.Count(x => x.beef_dairy_stat == true && x.param_id == 1) })
                    .AsEnumerable()
                    .Select(y => new Tuple<int, int>(y.month, y.icc_count))
                    .ToList();
var sql_rez_ICC=new List();
sql\u rez\u ICC=db.user\u行为\u事实
.其中(x=>x.fact\u date.Value.Year==所选的\u年)
.GroupBy(y=>y.fact\u date.Value.Month)
.Select(y=>new{month=y.Select(x=>x.fact\u date.Value.month),icc\u count=y.count(x=>x.beef\u dairy\u stat==true&&x.param\u id==1)})
.可计算的()
.Select(y=>新元组(y.month,y.icc\u count))
.ToList();
然而,在第二个
。选择
,我在月份得到一个错误

无法从System.Collection.Generic.IEnumrable转换为int

y.Select(x=>x.fact\u date.Value.Month)
返回一个
IEnumerable
。改为使用y键