-2

I am trying this but it doesn't work how can i correct this.

Actually i faced two conditions in both the case first i need to check if record exist, in first case if it exist i want assign some value not from edmx, in second case if record exist i want to assign value from the edmx file.

IsPriceApplied = cn.OrderDressings.Any(x => x.OrderID == OrderID && x.OrderItemID == ProductID) ?(from yy in cn.OrderDressings where yy.OrderID==OrderID && yy.OrderItemID==ProductID select yy.IsPriceApplied):Do Nothing

As you can see i am using any to check the record first.

 _allAppliedItemList.AddRange((from xx in DressingItems
     where xx.DressingInfo.CatID == item.CategoryID
     select new btnObject()
     {
        CustomizationType = CategoryType.Dressing,
        BtnName = xx.DressingInfo.Description,
        Price = (double)xx.DressingInfo.MainPrice,
        IsSelected = xx.IsDefault,
        MaxLimit = item.DefaultFreeCount,
        CategoryID = xx.DressingInfo.CatID,
        IsDefaultLimit = item.IsDefaultLimit,
        ID = xx.DressingInfo.DressingID,
        ButtonColor = cn.OrderDressings.Any(x => x.OrderID == OrderID && x.OrderItemID == ProductID) 
            ? ButtonColor.Green 
            : ButtonColor.Red,
        catName = item.CatName,
        IsPriceApplied = cn.OrderDressings.Any(x => x.OrderID == OrderID && x.OrderItemID == ProductID) 
            ? (from yy in cn.OrderDressings where yy.OrderID==OrderID && yy.OrderItemID==ProductID select yy.IsPriceApplied)
            : noting
    }
).ToList());
4

1 回答 1

1

你不能做你想做的事。像这样更清晰,更容易理解:

bool priceApplied = cn.OrderDressings.Any(x => x.OrderID == OrderID && x.OrderItemID == ProductID);

if (priceApplied) {
    var query = (from yy in cn.OrderDressings
                where yy.OrderID == OrderID &&  
                      yy.OrderItemID == ProductID
               select yy.IsPriceApplied);
    // do stuff.
}

// else.. do nothing.
于 2013-09-18T06:21:49.683 回答