-1
 IQueryable<GRNDetail> selectedResults = from c in InventoryContext.GRNDetails
                              where c.ProductID == pro.ProductID && (c.Quantity - c.SoldQuantity > 0 || c.SoldQuantity.Value.Equals(null))
                              select new
                              {
                                  c.GRNDetailID,
                                  c.GRNID,
                                  c.Product,
                                  c.ProductID,
                                  c.PurchaseOrderDetail,
                                  c.PurchaseOrderDetailID,

                                  c.Quantity,
                                  c.SoldQuantity,
                                  c.Tax,
                                  c.TaxRate,
                                  c.Total,
                                  c.UnitPrice, 
                                  SaleQty = (c.Quantity - c.SoldQuantity)
                              };
4

1 回答 1

4

您缺少您的类型:选择中的 GRNDetail:
select new GRNDetail

编辑:或者使用Select c; 带回整个对象。或者,如果您只想要某些项目,您也可以创建自定义类型。

您可以像这样创建自定义类型:使用您的 SaleQty(设置为货币或双精度或任何适合您需要的数据类型:并将其用于您的结果:

 public class GRNDetailResults
    {
        public int GRNDetailID { get; set; }

        public int GRNID { get; set; }

        etc ....

        public double SaleQty { get; set; }

例如

IQueryable<GRNDetailResults> selectedResults = from c in InventoryContext.GRNDetails
                              where c.ProductID == pro.ProductID && (c.Quantity - c.SoldQuantity > 0 || c.SoldQuantity.Value.Equals(null))
                              select new GRNDetailResults
                              {
                                 GRNDetailID = c.GRNDetailID,
                                  GRNID  =c.GRNID, 
                                   etc ...
                                  SaleQty = (c.Quantity - c.SoldQuantity)
                              };
于 2013-09-09T13:50:37.730 回答