F#:使用 FluntNHibernate 时查找不确定类型的对象
我尝试通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对此一无所知,但通过在网上搜索 API 文档,我会尝试
更改
为
因为这个
http://fluentnhibernate.org/api/FluentNHibernate .Cfg.Db/PersistenceConfiguration%602.htm#ConnectionString
向我表明这可能是
c
的类型。编辑:(
显然类型是
MsSqlConnectionStringBuilder
。)无论如何,更一般地说,如果您遇到 F# 在 C# 时不推断 lambda 类型,那么
Action
或Func
,最简单的方法是显式添加
Action
或Func
委托类型,以便 F#正确解决过载问题。对于这种情况,我觉得改一下就
可以解决,这往往是最便捷的解封方式。
I don't know anything about this, but from searching the web for API docs, I would try
changing
to
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
Action
orFunc
and the easiest thing is to explicitly add the
Action
orFunc
delegate type so that F# correctly resolves the overload. In this case, I think changingto
fixes it, and this is often the most expedient way to get unblocked.
不知道为什么,但声明函数参数的类型是有效的:
无论如何,你最好使用 FunctionalNHibernate< /a> 代替 F# 中的 FluentNHibernate。
Not sure why, but declaring the type of the function parameter works:
Anyway, you'll be better off using FunctionalNHibernate instead of FluentNHibernate in F#.