这是我工作的TSQL。我正在努力将其转换为LINQ并在集合中产生结果。非常感谢提前
select p.CoreSPID as SPID,
sum(case when pp.PricingCategory = 'Water' and pp.WholesalePricing=0 then pp.FixedCharge end) RetailWaterFixed,sum(case when pp.PricingCategory = 'Water' and pp.WholesalePricing=0 then pp.VolumetricCharge end) RetailWaterVar
from PremisePricings pp,Premises p
and p.PremiseId = pp.PremiseId
group by p.CoreSPID
UNION
select p.CoreSPID as SPID,
sum(case when pp.PricingCategory = 'Water' and pp.WholesalePricing=0 then pp.FixedCharge end) RetailWaterFixed,sum(case when pp.PricingCategory = 'Water' and pp.WholesalePricing=0 then pp.VolumetricCharge end) RetailWaterVar
from PremiseMeteredPricings pp,Premises p,PremiseMeters pm
and p.PremiseId = pm.PremiseId and pm.PremiseMeterId = pp.PremiseMeterId
group by p.CoreSPID
答案 0 :(得分:0)
如果您对数据库有任何控制权,最简单的解决方案是使用视图:
您的代码可能如下所示:
List<AllPricing> list = db.AllPricings.ToList();
答案 1 :(得分:0)
var uniondemo = (from p in dc. PremisePricings
select new { Filename = p.filename, Size = p.size }).Union(
from k in dc. PremisePricings2
select new ({SPID=p.CoreSPID })
.sum(case when pp.PricingCategory = 'Water' and pp.WholesalePricing=0 then
pp.FixedCharge end) as RetailWaterFixed,sum(case when pp.PricingCategory = 'Water' and
pp.WholesalePricing=0 then pp.VolumetricCharge end) as VolumetricCharge ;