C# 将动态LINQ库与联接一起使用
以下是用户界面: 这是我用来激发动态where子句的代码片段:C# 将动态LINQ库与联接一起使用,c#,linq-to-sql,dynamic-linq,C#,Linq To Sql,Dynamic Linq,以下是用户界面: 这是我用来激发动态where子句的代码片段: public void bind() { string filter = ""; if (!string.IsNullOrEmpty(txtPart.Text)) { filter = filter + "masterinv.inv_item_id = " + txtPart.Text; } if (
public void bind()
{
string filter = "";
if (!string.IsNullOrEmpty(txtPart.Text))
{
filter = filter + "masterinv.inv_item_id = " + txtPart.Text;
}
if (!string.IsNullOrEmpty(txtDescription.Text))
{
if (!string.IsNullOrEmpty(filter))
{
filter = filter + " || masterinv.description = " + txtDescription.Text;
}
else
{
filter = filter + "masterinv.description = " + txtDescription.Text;
}
}
if (!string.IsNullOrEmpty(txtVendor.Text))
{
if (!string.IsNullOrEmpty(filter))
{
filter = filter + " || vendor.vendor_name = " + txtVendor.Text;
}
else
{
filter = filter + "vendor.vendor_name = " + txtVendor.Text;
}
}
InventoryDataContext dc = new InventoryDataContext(InventoryDBContext.GetConnectionstring());
var searchResult = (from masterinv in dc.OMS_REF_Master_Inventories
join vendor in dc.OMS_REF_Vendors on masterinv.inv_item_id equals vendor.inv_item_id
Where(filter)
select new OMS_REF_Master_Inventory
{
inv_item_id = masterinv.inv_item_id,
description = masterinv.description,
unit_of_measure = masterinv.unit_of_measure,
lot_id = masterinv.lot_id,
serial_id = masterinv.serial_id,
mfg_id = masterinv.mfg_id,
mfg_item_id = masterinv.mfg_item_id,
item_status_current = masterinv.item_status_current,
cm_unit_cost = masterinv.cm_unit_cost,
sync_dte = masterinv.sync_dte
}).ToList();
searchResult;
}
在上述代码过滤器的基础上创建组合框和文本字段的组合
选择
其中一个过滤器是:
masterinv.inv_item_id = 'A' || masterinv.description = 'F' || vendor.vendor_name = 'V'
根据组合框值的选择,它可能会有所不同。BuildQueryFilter方法中存在组合框的所有情况 问题:
我无法在此联接中激发where子句。哪里出了问题?我认为不能将这些
%
用于linq查询
您可以使用Contains()/StartsWith()/EndsWith()
请参阅此以了解更多信息
或
使用Sql方法
where SqlMethods.Like(c.CustomerName, "%/abc/%")
放一个断点并检查您的最终筛选子句有什么?这是我得到的筛选器:masterinv.inv\u item\u id(如“%a%”)或masterinv.description(如“F%”)或vendor.vendor\u name(如“%V”)。它可能会根据组合框值的选择而有所不同。好的,忽略%。您可以使用简单的等号并使用where子句运行吗?可以,然后你不需要像这样的关键字,而不是那些你可以使用符号的关键字。不要使用像或/和这样的关键字,而是使用逻辑运算符
| |,&&&&
,并且你必须在将=改为==在你这边的哪里工作之后将=改为=
?