Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can someone help convert this SQL to LINQ?
Message
 
To
All
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Can someone help convert this SQL to LINQ?
Environment versions
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01605212
Message ID:
01605212
Views:
41
I'm stumped on this. Can someone please help me out on this? Thanks in Advance!

The problem comes in the Sum of pos.balance * coalesce(units.formula,1). See my lame LINQ below...
select sum(pos.balance * coalesce(units.formula,1)) as on_order,poi.uniq_key
FROM  mvw_PoItems poi
join mvw_PoMain pom
	on pom.ponum = poi.ponum
join mvw_SupplierInfo si
	on pom.UNIQSUPNO = si.UNIQSUPNO
join mvw_PoItemsSchedule pos
	on poi.uniqlnno = Pos.uniqlnno
join mvw_Inventory inv
	on inv.uniq_key = poi.uniq_key
left join mvw_Units units
	on [units].[from] = inv.pur_lunit
where pom.postatus not in ('CANCEL','CLOSED')
	and pos.balance <> 0
	and poi.poittype <> 'MRO'
	and poi.lcancel <> 1
group by poi.uniq_key
order by poi.uniq_key
var NotInStatuses = new string[] {"CANCEL","CLOSED"};
NotInStatuses.Dump();

var query = from poi in mvw_PoItems
join pom in mvw_PoMain
	on poi.ponum equals pom.ponum
join si in mvw_SupplierInfo
	on pom.uniqsupno equals si.uniqsupno
join pos in mvw_PoItemsSchedule
	on poi.uniqlnno equals pos.uniqlnno
join inv in mvw_Inventory
	on poi.uniq_key equals inv.uniq_key
join units in mvw_Units
	on inv.pur_lunit equals units.to into unitsjoin
	from myUnits in unitsjoin.DefaultIfEmpty()
where !NotInStatuses.Contains(pom.postatus)
	&& pos.balance != 0
	&& poi.poittype != "MRO"
	&& poi.lcancel != true
orderby poi.uniq_key	
group new {poi, pos, myUnits} by new {poi.uniq_key} into g
	select new 
	{
		uniq_key = g.Key,
		on_order = g.Sum(x => (decimal?)x.pos.balance * x.myUnits.formula ?? (decimal?)1)
	};

query.Dump();	//Using LinqPad to try to figure this out.
Next
Reply
Map
View

Click here to load this message in the networking platform