LINQ Data Normalization

I use OMS, which stores up to three write positions in the database.

The following is an example of an order containing five 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 to have a one-to-one relationship for information records (ie, one detailed record for each item). I used to use an UNION ALLSQL statement to retrieve data. Is there a better approach to this problem using LINQ?

The following is the first attempt to use LINQ. Any feedback, suggestions or recommendations would be greatly appreciated. For what I read, UNIONcan an operator 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 });
+3
1

Id

class Record 
{
    public object SubHeading { get; set; }
    public int EdpNo { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
}

var orders = context.ORDERSUBHEADs.Select(o => 
   new Record[] {
      new Record { SubHeading = o, EdpNo = o.EDPNOS_001, Price = o.EXTPRICES_001, Quantity = o.ITEMQTYS_001 },
      new Record { SubHeading = o, EdpNo = o.EDPNOS_002, Price = o.EXTPRICES_002, Quantity = o.ITEMQTYS_002 },
      new Record { SubHeading = o, EdpNo = o.EDPNOS_003, Price = o.EXTPRICES_003, Quantity = o.ITEMQTYS_003 }
   }
);

IEnumerable allOrders = IEnumerable.Empty;
foreach(Record[] r in orders)
    allOrders = allOrders.Concat(r);

IEnumerable allRecords = allOrders.Cast<Record>();

, , o , IEnumerable IList -, #Parameters * #Rows.

+1

Source: https://habr.com/ru/post/1744821/


All Articles