我正在尝试Like
通过使用实体框架查询来实现运算符。但它似乎Like
不受int
列的支持。
这是我的查询:
using (ObjectContext ctx = new ObjectContext(gbcDbConnection.eObjqueryConnection))
{
string result = " Select ";
result += " master_factory.FACTORY_ID, master_factory.FACTORY_NAME, ";
result += " case when master_factory.FACTORY_TYPE ='"
+ gbvArticleVarieble.FactoryTypeExterIni+"' then '"
+ gbvArticleVarieble.FactoryTypeExter+"' else '"
+ gbvArticleVarieble.FactoryTypeInter+"' end as factory_type ";
result += " FROM ";
result += " LEWREDBEntities.[MASTER_FACTORY] as master_factory ";
result += " WHERE ";
result += " (master_factory.FACTORY_TYPE = @factoryType1 or master_factory.FACTORY_TYPE =@factoryType2) and master_factory.STATUS<>@status";
if (searchVal != "")
{
result += " AND master_factory.[FACTORY_ID] LIKE '%' + @searchVal + '%' ";
}
ObjectQuery<DbDataRecord> query = ctx.CreateQuery<DbDataRecord>(result);
query.Parameters.Add(new ObjectParameter("status", gbcDBVariable.DeleteIni));
query.Parameters.Add(new ObjectParameter("factoryType1",gbvArticleVarieble.FactoryTypeExterIni ));
query.Parameters.Add(new ObjectParameter("factoryType2", gbvArticleVarieble.FactoryTypeInterIni));
if (searchVal != "")
{
query.Parameters.Add(new ObjectParameter("searchValue", searchVal));
}
if (logger.IsDebugEnabled)
{
query.ToTraceString();
}
如您所见,Factory id 是整数数据类型。当我执行它时,它返回一个错误:
LIKE 参数必须是字符串类型。近成员访问表达式
有没有其他人尝试过这个?