LINQ to SQL 查询,其中字符串以通用列表中的元素开头
由于搜索要求发生了变化,我希望更新我的查询之一。最初,用户要输入单个 SKU 和制造商。搜索产品目录的日期范围。所以这就是我用的。
DateTime startDate = ...;
DateTime endDate = ...;
string prodSKU = TextSKU.Text.Trim();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
&& c.sku.StartsWith(prodSKU)
select c;
现在的要求是,用户可以在文本框中输入逗号分隔的 SKU 列表进行搜索。我困惑的是如何找到 mfg 中的所有产品。以 skuList 中的任何 SKU 开头的日期范围(不使用 fornext 循环)。
string prodSKU = TextSKU.Text.Trim();
List<string> skuList = prodSKU.Split(new char[] { ', ' }).ToList();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
// && c.sku.StartsWith(prodSKU)
select c;
任何想法将不胜感激!
I'm looking to update one of my queries as the requirements for the search has changed. Originally, the user was to enter a single SKU and a mfg. date range to search the product catalog. So this is what I used.
DateTime startDate = ...;
DateTime endDate = ...;
string prodSKU = TextSKU.Text.Trim();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
&& c.sku.StartsWith(prodSKU)
select c;
Now the requirement says that the user can enter a comma delimted list of SKUs into the textbox to search. What I'm stumped about is how to find all the products in the mfg. date range that begin with any of the SKUs in skuList (w/o using a fornext loop).
string prodSKU = TextSKU.Text.Trim();
List<string> skuList = prodSKU.Split(new char[] { ', ' }).ToList();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
// && c.sku.StartsWith(prodSKU)
select c;
Any ideas would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西
Something like
编辑:即使这个问题已经得到解答,我也会把它放在这里。
我实现了与接受的解决方案相同的效果,但使用扩展方法来提高可读性:
然后解决方案是:
EDIT: I'll put this here even though this question is already answered.
I achieved the same as the accepted solution, but using an extension method to aid readability:
and then the solution is: