动态 LINQ API - SQL 转换函数
我正在尝试使用动态 LINQ 查询来查询 SQL 数据库,并且在 Where 子句中我需要使用 TEXT 类型的字段来评估“=”条件。
现在,我得到了这个:
var result = DBCon.PcInValue
.Where(String.Format("InputName = @0 and InputValue) {0} @1", f.Condition), f.Field, f.Value)
.Select("new(OrderNum, OrderLine)");
这不起作用,因为您不能在 TEXT 数据类型上使用等于运算符。 TEXT 类型的字段是“InputValue”。我尝试像这样转换它:
var result = DBCon.PcInValue
.Where(String.Format("InputName = @0 and Convert(nvarchar(100), InputValue) {0} @1", f.Condition), f.Field, f.Value)
.Select("new(OrderNum, OrderLine)");
但看起来这不受支持。
有人知道我该如何做到这一点吗?
编辑: 以下 SQL 语法可以正常工作,但我再次不确定是否可以使用动态 LINQ API:
SELECT [t0].[OrderNum], [t0].[OrderLine]
FROM [PcInValue] AS [t0]
WHERE ([t0].[InputName] = 'OpenWidthFt') AND (Convert(nvarchar(100), [t0].[InputValue]) = '10')
I'm trying to use a Dynamic LINQ Query to query a SQL database, and in the Where clause I need to evaluate an '=' condition with a field that is of type TEXT.
Right now, I've got this:
var result = DBCon.PcInValue
.Where(String.Format("InputName = @0 and InputValue) {0} @1", f.Condition), f.Field, f.Value)
.Select("new(OrderNum, OrderLine)");
This doesn't work since you can't use the equal operator on a TEXT data type.
The field that is type TEXT is "InputValue". I tried to convert it like so:
var result = DBCon.PcInValue
.Where(String.Format("InputName = @0 and Convert(nvarchar(100), InputValue) {0} @1", f.Condition), f.Field, f.Value)
.Select("new(OrderNum, OrderLine)");
But it looks like this is not supported.
Anyone have any clues as to how I can do this?
EDIT:
The following SQL Syntax works with no issues, but again I'm not sure if this is possible using the Dynamic LINQ API:
SELECT [t0].[OrderNum], [t0].[OrderLine]
FROM [PcInValue] AS [t0]
WHERE ([t0].[InputName] = 'OpenWidthFt') AND (Convert(nvarchar(100), [t0].[InputValue]) = '10')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经对此进行了测试,它似乎工作正常(尽管有点奇怪):
LinqPad 告诉我它已转换为类似于以下内容的内容(使用我自己的表格):
I've tested this and it seems to work fine (though it's a bit odd):
LinqPad tells me it's translated into something similar to the following (using my own table):