F#:使用 FluntNHibernate 时查找不确定类型的对象

发布于 2024-10-03 11:19:55 字数 465 浏览 4 评论 0原文

我尝试通过 FluentNHibernate 在 F# 项目中配置 NHibernate。

 static member GetNHibernateConfig = 
    Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
                .ConnectionString(fun c -> c.FromConnectionStringWithKey("connectionString") |> ignore)
                    .ShowSql())

Visual Studio 突出显示“c.FromConnectionStringWithKey”并显示错误:

根据此程序点之前的信息查找不确定类型的对象。在此程序点之前可能需要类型注释来约束对象的类型。这可以使查找得以解决。

I try to configure NHibernate in F# project by FluentNHibernate.

 static member GetNHibernateConfig = 
    Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
                .ConnectionString(fun c -> c.FromConnectionStringWithKey("connectionString") |> ignore)
                    .ShowSql())

Visual Studio highlight "c.FromConnectionStringWithKey" with error:

Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷清清 2024-10-10 11:19:55

我对此一无所知,但通过在网上搜索 API 文档,我会尝试
更改

fun c ->

fun (c:ConnectionStringBuilder) -> 

因为这个

http://fluentnhibernate.org/api/FluentNHibernate .Cfg.Db/PersistenceConfiguration%602.htm#ConnectionString

向我表明这可能是 c 的类型。

编辑:(

显然类型是 MsSqlConnectionStringBuilder。)

无论如何,更一般地说,如果您遇到 F# 在 C# 时不推断 lambda 类型,那么

  • 您可能正在使用具有多个重载的方法
  • 的某些子集重载使用 ActionFunc

,最简单的方法是显式添加 ActionFunc 委托类型,以便 F#正确解决过载问题。对于这种情况,我觉得改一下

.ConnectionString(fun c -> ...)

.ConnectionString(Action<MsSqlConnectionStringBuilder>(fun c -> ...))

可以解决,这往往是最便捷的解封方式。

I don't know anything about this, but from searching the web for API docs, I would try
changing

fun c ->

to

fun (c:ConnectionStringBuilder) -> 

because this

http://fluentnhibernate.org/api/FluentNHibernate.Cfg.Db/PersistenceConfiguration%602.htm#ConnectionString

suggests to me that that may be the type of c.

EDIT:

(Apparently the type is MsSqlConnectionStringBuilder.)

Anyway, more generally, if you run into F# not inferring lambda types when C# does, then probably

  • you're using a method with multiple overloads
  • some subset of the overloads use Action or Func

and the easiest thing is to explicitly add the Action or Func delegate type so that F# correctly resolves the overload. In this case, I think changing

.ConnectionString(fun c -> ...)

to

.ConnectionString(Action<MsSqlConnectionStringBuilder>(fun c -> ...))

fixes it, and this is often the most expedient way to get unblocked.

朱染 2024-10-10 11:19:55

不知道为什么,但声明函数参数的类型是有效的:

Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString(fun (c: MsSqlConnectionStringBuilder) -> c.FromConnectionStringWithKey("connectionString") |> ignore)
                .ShowSql())

无论如何,你最好使用 FunctionalNHibernate< /a> 代替 F# 中的 FluentNHibernate。

Not sure why, but declaring the type of the function parameter works:

Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString(fun (c: MsSqlConnectionStringBuilder) -> c.FromConnectionStringWithKey("connectionString") |> ignore)
                .ShowSql())

Anyway, you'll be better off using FunctionalNHibernate instead of FluentNHibernate in F#.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文