开发者

F#: Lookup on object of indeterminate type When using FluntNHibernate

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

 static member GetNHibernateConfig = 
    Fluently.Configure()
            .Database(MsSqlConfigurati开发者_StackOverflow中文版on.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.


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.


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#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜