Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Types F型混淆-I';我相信我';我得到了我需要的值,但是编译器在运行时不同意_Types_F#_Functional Programming_Type Providers - Fatal编程技术网

Types F型混淆-I';我相信我';我得到了我需要的值,但是编译器在运行时不同意

Types F型混淆-I';我相信我';我得到了我需要的值,但是编译器在运行时不同意,types,f#,functional-programming,type-providers,Types,F#,Functional Programming,Type Providers,我有一个很好的QC测试工具,我可以通过VB从现有的设置中访问它。这个工具给我提供了对表的强类型访问,而无需创建新的类等。然而,遗憾的是,其中一个表使用了逗号而不是子表 这个社区主义者给我带来了麻烦。理论上,下面的代码应该拆分row.commalist,然后告诉我给定的数字是否在 我能够从CommaListValues位输出值-这是布尔值。我给它提供了给定的参数,编译器似乎很高兴 为什么它在运行时不使用布尔值作为标准?我想我有精神障碍——我不经常使用F,但我非常想——不幸的是,这些小家伙占用了我的

我有一个很好的QC测试工具,我可以通过VB从现有的设置中访问它。这个工具给我提供了对表的强类型访问,而无需创建新的类等。然而,遗憾的是,其中一个表使用了逗号而不是子表

这个社区主义者给我带来了麻烦。理论上,下面的代码应该拆分row.commalist,然后告诉我给定的数字是否在

我能够从CommaListValues位输出值-这是布尔值。我给它提供了给定的参数,编译器似乎很高兴

为什么它在运行时不使用布尔值作为标准?我想我有精神障碍——我不经常使用F,但我非常想——不幸的是,这些小家伙占用了我的时间

有人能帮忙吗

按要求编辑。commalist样本的典型值为:“234132546344243677”

模块质量控制
开放系统
open System.Collections.Generic
开放系统.数据
开放系统.Data.Linq
打开Microsoft.FSharp.Data.TypeProviders
打开Microsoft.FSharp.Linq
类型dbschema=SqlDataConnection
设db=dbschema.GetDataContext()
类型质量检查(SingleIDToMatch)=
让问题列表(q:string,SingleIDToMatch:string)=q.Split[|','|][124;>fun x->x.Equals(SingleIDToMatch)
成员x.MatchID=
质疑{
对于db.SomeTableWithCommaListColumn do中的行
其中(问题列表(row.CommaListValue,System.Convert.ToString(SingleIDToMatch)))
选择行}
我得到以下错误:

发生System.ArgumentException异常 HResult=-2147024809 Message=参数“value”的类型错误。应为“System.Func
2[System.Tuple
2[System.String,System.String],System.Boolean]”。实际的“System.Boolean”。 Source=System.Data.Linq 堆栈跟踪: 位于System.Data.Linq.SqlClient.SqlMethodCall.set_对象(SqlExpression值) 位于System.Data.Linq.SqlClient.SqlMethodCall..ctor(类型clrType、ProviderType sqlType、MethodInfo方法、SqlExpression obj、IEnumerable
1参数、表达式sourceExpression)
位于System.Data.Linq.SqlClient.SqlFactory.MethodCall(MethodInfo方法,SqlExpression obj,SqlExpression[]参数,Expression sourceExpression)
位于System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
位于System.Data.Linq.SqlClient.QueryConverter.VisitInner(表达式节点)
位于System.Data.Linq.SqlClient.QueryConverter.VisitExpression(表达式exp)
位于System.Data.Linq.SqlClient.QueryConverter.VisitWhere(表达式序列,LambdaExpression谓词)
在System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)中
位于System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
位于System.Data.Linq.SqlClient.QueryConverter.VisitInner(表达式节点)
位于System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(表达式节点)
位于System.Data.Linq.SqlClient.SqlProvider.BuildQuery(表达式查询、SqlNodeAnnotations注释)
位于System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)
位于System.Data.Linq.DataQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator()处 在删除的项目详细信息中
InnerException:

类型提供程序尝试将查询表达式转换为SQL,但它无法将
questionList()
调用转换为
WHERE
子句。简单的解决方案是将
MatchID()
更改为如下所示:

member x.MatchID=
    let idString = singleIDToMatch.ToString()
    query {
        for row in db.SomeTableWithCommaListColumn do
        where (row.CommaListValue.EndsWith("," + idString)
            || row.CommaListValue.StartsWith(idString + ",")
            || row.CommaListValue.Contains("," + idString + ","))
        select row }
let withAtLeast10Characters (q : Linq.IQueryable<dbschema.ServiceTypes.SomeTableWithCommaListColumn>) =
    query {
        for row in q do
        where (row.CommaListValue.Length >= 10)
        select row }

let result = qualityChecks.MatchID |> withAtLeast10Characters
SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  (DATALENGTH([t0].[CommaListValue]) >= @p0)
       AND (([t0].[CommaListValue] LIKE @p1)
            OR ([t0].[CommaListValue] LIKE @p2)
            OR ([t0].[CommaListValue] LIKE @p3))
这将执行以下SQL:

SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  ([t0].[CommaListValue] LIKE @p0)
       OR ([t0].[CommaListValue] LIKE @p1)
       OR ([t0].[CommaListValue] LIKE @p2)
(参数包括适当的通配符,以给出与查询表达式中的F#代码等效的结果)


作文 如果需要组合多个
WHERE
子句,可以链接查询表达式,如下所示:

member x.MatchID=
    let idString = singleIDToMatch.ToString()
    query {
        for row in db.SomeTableWithCommaListColumn do
        where (row.CommaListValue.EndsWith("," + idString)
            || row.CommaListValue.StartsWith(idString + ",")
            || row.CommaListValue.Contains("," + idString + ","))
        select row }
let withAtLeast10Characters (q : Linq.IQueryable<dbschema.ServiceTypes.SomeTableWithCommaListColumn>) =
    query {
        for row in q do
        where (row.CommaListValue.Length >= 10)
        select row }

let result = qualityChecks.MatchID |> withAtLeast10Characters
SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  (DATALENGTH([t0].[CommaListValue]) >= @p0)
       AND (([t0].[CommaListValue] LIKE @p1)
            OR ([t0].[CommaListValue] LIKE @p2)
            OR ([t0].[CommaListValue] LIKE @p3))

类型提供程序尝试将查询表达式转换为SQL,但无法将
questionList()
调用转换为
WHERE
子句。简单的解决方案是将
MatchID()
更改为如下所示:

member x.MatchID=
    let idString = singleIDToMatch.ToString()
    query {
        for row in db.SomeTableWithCommaListColumn do
        where (row.CommaListValue.EndsWith("," + idString)
            || row.CommaListValue.StartsWith(idString + ",")
            || row.CommaListValue.Contains("," + idString + ","))
        select row }
let withAtLeast10Characters (q : Linq.IQueryable<dbschema.ServiceTypes.SomeTableWithCommaListColumn>) =
    query {
        for row in q do
        where (row.CommaListValue.Length >= 10)
        select row }

let result = qualityChecks.MatchID |> withAtLeast10Characters
SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  (DATALENGTH([t0].[CommaListValue]) >= @p0)
       AND (([t0].[CommaListValue] LIKE @p1)
            OR ([t0].[CommaListValue] LIKE @p2)
            OR ([t0].[CommaListValue] LIKE @p3))
这将执行以下SQL:

SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  ([t0].[CommaListValue] LIKE @p0)
       OR ([t0].[CommaListValue] LIKE @p1)
       OR ([t0].[CommaListValue] LIKE @p2)
(参数包括适当的通配符,以给出与查询表达式中的F#代码等效的结果)


作文 如果需要组合多个
WHERE
子句,可以链接查询表达式,如下所示:

member x.MatchID=
    let idString = singleIDToMatch.ToString()
    query {
        for row in db.SomeTableWithCommaListColumn do
        where (row.CommaListValue.EndsWith("," + idString)
            || row.CommaListValue.StartsWith(idString + ",")
            || row.CommaListValue.Contains("," + idString + ","))
        select row }
let withAtLeast10Characters (q : Linq.IQueryable<dbschema.ServiceTypes.SomeTableWithCommaListColumn>) =
    query {
        for row in q do
        where (row.CommaListValue.Length >= 10)
        select row }

let result = qualityChecks.MatchID |> withAtLeast10Characters
SELECT [t0].[CommaListValue]
FROM   [dbo].[SomeTableWithCommaListColumn] AS [t0]
WHERE  (DATALENGTH([t0].[CommaListValue]) >= @p0)
       AND (([t0].[CommaListValue] LIKE @p1)
            OR ([t0].[CommaListValue] LIKE @p2)
            OR ([t0].[CommaListValue] LIKE @p3))

这个错误发生在哪一行?另外,您能给我们一个
CommaListValue
列的示例吗?您能发布函数问题列表的代码吗?如果是这样,您的F代码不应该编译。因为where函数需要一个t->boolean列表,而不是t->boolean列表。对DB运行
查询时,您应该只使用可以转换为SQL的结构。由于
questionList
是一个本地函数,它无法被翻译,因此它不起作用(尽管实际错误有点奇怪…)我并不感到惊讶。这个错误发生在什么行号上?还有,你能给我们一个
CommaListValue
列的示例吗?你能发布你的函数问题列表代码吗?如果是这样,你的F代码不应该编译。因为where函数需要一个t->boolean列表,而不是t->boolean列表。对DB运行
查询时,您应该只使用可以转换为SQL的结构。由于
questionList
是一个本地函数,因此无法对其进行翻译,因此它不起作用(尽管实际错误有点奇怪…)我并不感到惊讶。谢谢!我已经有一段时间没看这个了。谢谢!我已经有一段时间没看这个了。