# Nullable Linq

**URL:** <https://www.epiusers.help/t/nullable-linq/77315>\
**Category:** Epicor ERP 10\
**Tags:** customization, e10\
**Created:** [April 6, 2021, 7:11am UTC](https://www.epiusers.help/t/nullable-linq/77315 "2021-04-06T07:11:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aarong](https://www.epiusers.help/user_avatar/www.epiusers.help/aarong/32/101218_2.png) [@aarong](https://www.epiusers.help/u/aarong)\
**Post date:** [April 6, 2021, 7:11am UTC](https://www.epiusers.help/t/nullable-linq/77315/1 "2021-04-06T07:11:39Z")

</div>

Hi all,

I need some help with a bit of code.

```auto
var CalcWeight = (from shipDtl in Db.ShipDtl
                   join part in Db.Part on shipDtl.PartNum equals part.PartNum
                   join orderDtl in Db.OrderDtl on shipDtl.PartNum equals orderDtl.PartNum
                   where shipDtl.PackNum == PackNum
                   select shipDtl.SellingInventoryShipQty * part.NetWeight
                   ).ToList().Sum();

using (var txScope = IceContext.CreateDefaultTransactionScope())
{

foreach (var ShipDtl in (from ShipDtlRow in Db.ShipDtl
where ShipDtlRow.Company == Session.CompanyID 
&& ShipDtlRow.PackNum == PackNum
select ShipDtlRow))
{
TotalWeight = Convert.ToDecimal(CalcWeight);
ShipDtl.ShippedWeight_c = Convert.ToDecimal(CalcWeight); 
}

 Db.Validate();
 txScope.Complete();
}   

```

This is currently working perfectly, but I need to introduce `OrderDtl.CustomWeight_c` if `part.NetWeight` is null and display a message if `part.NetWeight` not null and `OrderDtl.CustomWeight_c` has been used.

I have done the joins but I’m not sure how to do the other bits…

How would I achieve this? Thank you for your help.

---

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [April 6, 2021, 11:09am UTC](https://www.epiusers.help/t/nullable-linq/77315/2 "2021-04-06T11:09:43Z")

</div>

Try something like this

```cs
var CalcWeight = (from shipDtl in Db.ShipDtl
                   join part in Db.Part on new { shipDtl.Company, shipDtl.PartNum } equals new { part.Company, part.PartNum }
                   join orderDtl in Db.OrderDtl on new { shipDtl.Company, shipDtl.PartNum } equals new { orderDtl.Company, orderDtl.PartNum }
                   where shipDtl.Company == Session.CompanyID && shipDtl.PackNum == PackNum
                   select shipDtl.SellingInventoryShipQty * (part.NetWeight != 0 ? part.NetWeight : orderDtl.CustomWeight_c)
                   ).ToList().Sum();

```

Also always join on Company. PS: I dont think your OrderDtl is complete, you might need to join to OrderNum, OrderLine, OrderRelNum

---

<div class="post-metadata">

**Author:** ![aarong](https://www.epiusers.help/user_avatar/www.epiusers.help/aarong/32/101218_2.png) [@aarong](https://www.epiusers.help/u/aarong)\
**Post date:** [April 6, 2021, 11:12am UTC](https://www.epiusers.help/t/nullable-linq/77315/3 "2021-04-06T11:12:41Z")

</div>

Join OrderNum, OrderLine, OrderRelNum onto ShipDtl?

---

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [April 6, 2021, 11:14am UTC](https://www.epiusers.help/t/nullable-linq/77315/4 "2021-04-06T11:14:08Z")

</div>

```cs
var CalcWeight = (from shipDtl in Db.ShipDtl
                   join part in Db.Part on new { shipDtl.Company, shipDtl.PartNum } equals new { part.Company, part.PartNum }
                   join orderDtl in Db.OrderDtl on new { shipDtl.Company, shipDtl.OrderNum, shipDtl.OrderLine, shipDtl.OrderRelNum, shipDtl.PartNum } equals new { orderDtl.Company, orderDtl.OrderNum, orderDtl.OrderLine, orderDtl.OrderRelNum, orderDtl.PartNum }
                   where shipDtl.Company == Session.CompanyID && shipDtl.PackNum == PackNum
                   select shipDtl.SellingInventoryShipQty * (part.NetWeight != 0 ? part.NetWeight : orderDtl.CustomWeight_c)
                   ).ToList().Sum();

```
