3

我正在扩展 Fluent NHibernate 以便更好地与 F# 一起使用(即报价支持),并希望得到一些关于去流化 API 的反馈。F# 要求使用返回值,除非它们是类型单位。所以这最终以“|> ignore”终止每一行:

type ProductMap() as m = inherit QClassMap<Product>() do
    let x = Unchecked.defaultof<Product> 
    m.Id <@ x.Id @> |> ignore
    m.Map <@ x.Name @> |> ignore
    m.Map <@ x.Price @> |> ignore
    (m.HasManyToMany <@ seq x.StoresStockedIn @>)
        .Cascade.All()
        .Inverse()
        .WithTableName("StoreProduct") |> ignore

我的第一反应是向基类添加更多方法,以便它们返回单位。例如,“IdI”和“MapI”:

...
m.IdI <@ x.Id @>
m.MapI <@ x.Name @> 
m.MapI <@ x.Price @> 
... 

但这需要在这里和那里进行特定的重载,并且长链仍然需要 |> Ignore。我还考虑过使用 Done 属性扩展对象:

(m.Id <@ x.Id @>).Done
(m.Map <@ x.Name @>).Done
(m.Map <@ x.Price @>).Done
(m.HasManyToMany <@ seq x.StoresStockedIn @>)
    .Cascade.All()
    .Inverse()
    .WithTableName("StoreProduct").Done

你怎么看?

4

1 回答 1

4

IMHO a better approach would be to start from scratch thinking in F# (e.g function piping, currying, combinators) instead of wrapping fluent nhibernate, but using what fluent nhibernate has used to generate the mappings. That is, building a "parallel fluent nhibernate" for exclusive use of F#.

I've recently posted about a similar issue with Windsor's fluent interface in F#. My conclusion is that many DSLs / fluent interfaces built for C# / VB.NET will break in F# so I think it's best to build specific fluent interfaces that suit the F# way.

于 2009-04-07T06:25:39.833 回答