C#EntityFramework 6.0查询小数> 0不会给出结果

时间:2019-05-23 07:25:54

标签: c# entity-framework linq

所以我在这里设置了模型:

public class Stock
{
    [Key]
    //[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public Guid StockId { get; set; } = Guid.NewGuid();
    .....
    public decimal Remaining { get; set; }
}

还具有流畅的映射:

    protected override void OnModelCreating(DbModelBuilder mb)
    {
        base.OnModelCreating(mb);
        mb.HasDefaultSchema("dbo");

        mb.Entity<Stock>().Property(m => m.Remaining).HasPrecision(16, 3);
        ....
    }

所以精度是3个小数点。

当我用linq查询时,这太奇怪了:

IQueryable<StockDetail> stocks = (from s in db.Stocks .... where s.Remaining > 0);
stocks.Any() --> is false;

where s.Remaining > 0是问题,如何解决?


编辑

实际查询:

IQueryable<StockDetail> stocks = (from s in db.Stocks
    join items in db.Items on s.Item equals items.ItemId
    join types in db.ItemTypes on s.ItemType equals types.ItemTypeId
    join colors in db.ItemColors on s.ItemColor equals colors.ItemColorId
    join units in db.ItemUnits on s.Unit equals units.ItemUnitId
    join buyers in db.Buyers on new { Buyer = s.Buyer } equals new { Buyer = (Guid?)buyers.BuyerId } into temp2
    from buyers in temp2.DefaultIfEmpty(null)
    join suppliers in db.Suppliers.DefaultIfEmpty() on new { Supplier = s.Supplier } equals new { Supplier = (Guid?)suppliers.SupplierId } into temp3
    from suppliers in temp3.DefaultIfEmpty(null)
    join op in db.UserProfiles on s.Operator equals op.UserId
    join curr in db.Currencies on s.Currency equals curr.CurrencyId
    let sales = db.Sales.Where(m => m.SId == s.Sales).FirstOrDefault()
    join parent in db.Stocks on s.Parent equals parent.StockId
    where s.Remaining > 0 
    select new StockDetail()
    {
        Buyer = buyers != null ? (Guid?)buyers.BuyerId : null,
        BuyerName = buyers != null ? buyers.Name : null,
        Supplier = suppliers.SupplierId,
        SupplierName = suppliers.Name,
        Code = s.Code,
        Color = colors.ItemColorId,
        ColorCode = colors.Code,
        ColorName = colors.Color,
        DateCreated = s.DateCreated,
        Gramation = s.Gramation,
        Item = items.ItemId,
        ItemName = items.Name,
        LastEdited = s.LastEdited,
        Operator = op.UserId,
        OperatorName = op.UserName,
        PO = s.PO,
        Remaining = s.Remaining,
        SC = s.SC,
        Qty = s.Qty,
        Setting = s.ItemSetting,
        StockId = s.StockId,
        Type = types.ItemTypeId,
        TypeName = types.Type,
        Unit = units.ItemUnitId,
        UnitName = units.Unit,
        Lot = s.Lot,
        AvgPrice = s.AvgPrice,
        Currency = curr.CurrencyName,
        CurrencyId = s.Currency,
        Note = s.Note,
        Purchase = s.Purchase,
        Sales = s.Sales,
        POIn = s.POIn,
        FromFactory = s.FromFactory,
        OutDeliveryNo = sales != null ? sales.InvoiceNo : "",
        Spec = s.Spec,
        DesignCode = s.DesignCode
    });

0 个答案:

没有答案