Hi,
GetAttributeValue return default value of type you specify. So I would recommend to add check condition like below before adding it into the Entity object.
if(product.Attributes.Contains("zst_product") && product["zst_product"!=null)
orderProduct["productid" = product.GetAttributeValue<EntityReference>("zst_product");
if(product.Attributes.Contains(zst_quantity))
orderProduct["quantity"=product.GetAttributeValue<decimal>("zst_quantity"));
FYI, Sample Code to Create Sales Order Details Record from C#
public void goCreateObject(IOrganizationService service)
{
Entity orderDetail = new Entity("salesorderdetail");
Guid _soid = new Guid("660cf2c7-8c33-e711-8115-e00xxx");
Guid _pid = new Guid("1ace6e83-8b33-e711-8115-e007yyy");
Guid _uomid = new Guid("839e561d-17b8-4c8a-8baf-37zzz");
bool _price = false;
bool _product = false;
orderDetail.Attributes.Add("salesorderid", new EntityReference("salesorder", _soid));
orderDetail.Attributes.Add("productid", new EntityReference("product", _pid));
orderDetail.Attributes.Add("quantity", Convert.ToDecimal(1));
orderDetail.Attributes.Add("uomid", new EntityReference("uom", _uomid));
orderDetail("ispriceoverridden") = _price;
orderDetail("isproductoverridden") = _product;
Guid _orderDetailId = service.Create(orderDetail);
}
Please mark my answer verified if i were helpful