帮忙看看这个怎么成LINQ?
select
count(a.fund_id) n
from
t_fund_info as a
inner join t_fund_join_year as b
on a.fund_id = b.fund_id
inner join t_fund_type as c
on b.type = c.type_id
where a.status in(1,2) and
b.category = 19 and
c.type_id in (24,25) and
b.join_year = 0 and
b.status = 1
and exists(
select * from t_fund_org_index as i
where
i.org_type in(100043)
and a.fund_id = i.fund_id
and (i.is_current = 1 OR a.status = 2)
and exists(
select * from t_org_class as os
where os.class_type in (100053) and os.org_id = i.org_id
)
)
对linq语法不是很懂。请大家帮帮忙
------解决方案--------------------不懂 帮顶
------解决方案--------------------select
ti.fund_id,
ti.fund_name,
dbo.fun_get_org_mebmer(fund_id,1),
dbo.fun_get_org_info(fund_id,100050)
from
t_fund_info as a
inner join t_fund_join_year as b
on a.fund_id = b.fund_id
inner join t_fund_type as c
on b.type = c.type_id
where a.status in(1,2) and
b.category = 19 and
c.type_id in (24,25) and
b.join_year = 0 and
b.status = 1
and exists(
select * from t_fund_org_index as i
where
i.org_type in(100043)
and a.fund_id = i.fund_id
and (i.is_current = 1 OR a.status = 2)
and exists(
select * from t_org_class as os
where os.class_type in (100053) and os.org_id = i.org_id
)
)
其实sql的原型是这个
------解决方案--------------------
var query =(from a in db.t_fund_info
join b in db.t_fund_join_year on a.fund_id equals b.fund_id
join c in db.t_fund_type on b.type equals c.type_id
where
(
new int[]{1,2}
).Contains(a.status) && (b.category == 19) &&
(
new int[]{24,25}
).Contains(c.type_id) && (b.join_year == 0) &&(b.status == 1) &&
(db.t_fund_org_index.Any(c=>(c.org_type==100043)&&(a.fund_id = c.fund_id)&&(c.is_current == 1 || a.status == 2)&&(db.t_org_class.Any(d=>d.class_type==100053&&d.org_id==c.org_id)))
select a.fund_id).Count();
再试试这个,我都试过了,没有错误
顺便提下,你的这个也太长了
就不能分开来写吗
搞的这么长……
------解决方案--------------------
C# code
var query=(from a in db.t_fund_info
join b in db.t_fund_join_year
on a.fund_id equals b.fund_id
join c in db.t_fund_type
on b.type equals c.type_id
let temp= from i in db.t_fund_org_index
let t=db.t_org_class.Where(os=>new int[]{100053}.Contains(os.class_type)
&& os.org_id ==i.org_id)
where new int[]{100043}.Contains(i.org_type)
&& a.fund_id == i.fund_id
&& (i.is_current==1 || a.status==2)
&& t.Any()
select i //sorry for this place
where new int[]{1,2}.Contains(a.status)
&&new int[]{24,25}.Contains(c.type_id)
&& b.category==19 && b.join_year==0 && b.status==1
&& temp.Any()
select a.fund_id).Count();