LINQ to MYSQL 中的 Like 运算符
Like operator in LINQ to MYSQL
如何在 mysql 的 linq 中使用 like。请在下面查看我的代码。参数 productname 给出了输入值。但是当我 运行 这个查询时,结果没有出现。如何使用 mysql 提供商
执行此操作
public List<Product> GetProductsByProductName(string storeId, string productName)
{
Authenticate();
int _storeId = Convert.ToInt32(storeId);
var _products = (from p in context.products.AsEnumerable()
where p.StoreId == _storeId && p.ProductName.Contains(productName) && p.ProductIsAvailable.Equals(true)
orderby p.ProductName
select
new Product()
{
ProductName = p.ProductName,
CategoryID = p.CategoryId,
QuantityPerUnit = p.ProductUnit,
UnitPrice = p.ProductPrice,
DiscountValue = p.DiscountValue,
DiscountType = p.DiscountType,
ProductDescription = p.ProductDescription,
ProductURL = p.ProductURL,
ProductSmallDescription = p.ProductSmallDescription,
ProductListPrice = p.ProductListPrice
}).ToList();
}
在这里....如果是MySQL我们需要使用.ToLower()。请看下面的代码。
p.ProductName.ToLower().包含(productName.ToLower())
谢谢...
如何在 mysql 的 linq 中使用 like。请在下面查看我的代码。参数 productname 给出了输入值。但是当我 运行 这个查询时,结果没有出现。如何使用 mysql 提供商
执行此操作 public List<Product> GetProductsByProductName(string storeId, string productName)
{
Authenticate();
int _storeId = Convert.ToInt32(storeId);
var _products = (from p in context.products.AsEnumerable()
where p.StoreId == _storeId && p.ProductName.Contains(productName) && p.ProductIsAvailable.Equals(true)
orderby p.ProductName
select
new Product()
{
ProductName = p.ProductName,
CategoryID = p.CategoryId,
QuantityPerUnit = p.ProductUnit,
UnitPrice = p.ProductPrice,
DiscountValue = p.DiscountValue,
DiscountType = p.DiscountType,
ProductDescription = p.ProductDescription,
ProductURL = p.ProductURL,
ProductSmallDescription = p.ProductSmallDescription,
ProductListPrice = p.ProductListPrice
}).ToList();
}
在这里....如果是MySQL我们需要使用.ToLower()。请看下面的代码。
p.ProductName.ToLower().包含(productName.ToLower())
谢谢...