LINQ Normalizing data
- by Brennan Mann
I am using an OMS that stores up to three line items per record in the database.
Below is an example of an order containing five line items.
Order Header
Order Detail
Prod 1
Prod 2
Prod 3
Order Detail
Prod 4
Prod 5
One order header record and two detail records.
My goal is have a one to one relation for details records(i.e., one detail record per line item). In the past, I used an UNION ALL SQL statement to extract the data. Is there a better approcach to this problem using LINQ?
Below is my first attempt at using LINQ. Any feedback, suggestions or recommendations would greatly be appreciated. For what I have read, an UNION statement can tax the process?
var orderdetail =
(from o in context.ORDERSUBHEADs
select new {
edpNo = o.EDPNOS_001, price = o.EXTPRICES_001,
qty = o.ITEMQTYS_001 }
).Union(from o in context.ORDERSUBHEADs
select new { edpNo = o.EDPNOS_002, price = o.EXTPRICES_002,
qty = o.ITEMQTYS_002 }
).Union(from o in context.ORDERSUBHEADs
select new { edpNo = o.EDPNOS_003, price = o.EXTPRICES_003,
qty = o.ITEMQTYS_003 });