0

下午,

如果价格匹配,我想返回一个布尔值。我返回 3 个不同的价格,但是我需要比较 lowprice 和 amzprice 是否相同。如果他们是我也需要返回......

pricematched = true

以下是我当前的查询。

 var query = from a in dc.aProducts
             join t in dc.tProducts on a.sku equals t.sku
             join lp in dc.LowestPrices on a.asin equals lp.productAsin
             orderby t.title
             select new GetLowestPrices
             {
                 productAsin = lp.productAsin,
                 sku = t.sku,
                 title = t.title,
                 oprice = Convert.ToString(t.tPrice),
                 lowprice = Convert.ToString(lp.price),
                 amzprice = Convert.ToString(lp.tAmzPrice),
                 lastupdated = Convert.ToDateTime(lp.priceDate)
            };
            return query.ToList();

所有的帮助将不胜感激,谢谢。

4

3 回答 3

0
select new GetLowestPrices
         {
             productAsin = lp.productAsin,
             sku = t.sku,
             title = t.title,
             oprice = Convert.ToString(t.tPrice),
             lowprice = Convert.ToString(lp.price),
             amzprice = Convert.ToString(lp.tAmzPrice),
             lastupdated = Convert.ToDateTime(lp.priceDate),
             pricematched = lp.price == lp.tAmzPrice
        };

顺便说一句,为什么要对价格进行字符串处理?还:

return query.ToList();

如果你可以侥幸逃脱return query而不是列出清单,那就去做吧。

于 2012-08-28T15:03:33.543 回答
0

如果您可以将布尔值添加到现有对象中,它只会影响查询,如下所示:

 var query = from a in dc.aProducts
         join t in dc.tProducts on a.sku equals t.sku
         join lp in dc.LowestPrices on a.asin equals lp.productAsin
         orderby t.title
         select new GetLowestPrices
         {
             productAsin = lp.productAsin,
             sku = t.sku,
             title = t.title,
             oprice = Convert.ToString(t.tPrice),
             lowprice = Convert.ToString(lp.price),
             amzprice = Convert.ToString(lp.tAmzPrice),
             lastupdated = Convert.ToDateTime(lp.priceDate),
             pricematched = lp.tAmzPrice >= lp.price    // This should do it
        };
        return query.ToList();

否则,您必须在查询之外使用辅助查询:

var matchedItems = query.Where(x => x.amzprice >= x.lowprice);
于 2012-08-28T15:03:49.973 回答
0

我决定使用 jquery 来代替。

于 2012-08-28T15:52:29.617 回答