下午,
如果价格匹配,我想退回一个bool。我将返回3种不同的价格,但是我需要比较低价和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();
所有的帮助将非常感谢,谢谢。
答案 0 :(得分: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
而不是列表,那就去做吧。
答案 1 :(得分: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);
答案 2 :(得分:0)
我决定使用jquery来做这件事。