0
我現在正在研究F#的Entity Framework Code First Wrapper,我一直在想我是否應該將所有模塊合併到一個模塊中。F# - 合併模塊?
看看這個:
module ManyNavProperty =
let withMany (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithMany()
let withSeq expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithSeq expr
let withList expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithList expr
let withArray expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithArray expr
let withOptional (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithOptional()
let withOptionalProperty expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithOptional expr
let withRequired (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithRequired()
let withRequiredProperty expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithRequiredProperty expr
module DependentNavProperty =
let hasForeignKey expr (cfg:DependentNavPropertyInfo<'a>) = cfg.HasForeignKey expr
module CascadableNavProperty =
let willCascadeOnDelete b (cfg:CascadableNavPropertyInfo) = cfg.WillCascadeOnDelete b
module EF =
let entity<'a when 'a : not struct> (cfg:DbModelBuilder) = EntityInfo<'a>(cfg.Entity<'a>())
let hasKey expr (cfg:EntityInfo<'a>) = cfg.HasKey expr
let hasSeq expr (cfg:EntityInfo<'a>) = cfg.HasSeq expr
let hasList expr (cfg:EntityInfo<'a>) = cfg.HasList expr
let hasArray expr (cfg:EntityInfo<'a>) = cfg.HasArray expr
let hasOptional expr (cfg:EntityInfo<'a>) = cfg.HasOptional expr
let hasRequired expr (cfg:EntityInfo<'a>) = cfg.HasRequried expr
let toTable s (cfg:EntityInfo<'a>) = cfg.ToTable s
,要求我打電話給喜歡代碼:
override x.OnModelCreating (mb:DbModelBuilder) =
let finished = ignore
let entity = EF.entity<Author> mb
entity
|> EF.hasSeq <@ fun z -> z.Books @>
|> ManyNavProperty.withRequiredProperty <@ fun z -> z.Author @>
|> DependentNavProperty.hasForeignKey <@ fun z -> z.AuthorId @>
|> CascadableNavProperty.willCascadeOnDelete true
|> finished
就是利用這麼多的模塊,爲用戶混淆的? - 我是否應該將它們全部放入一個模塊中,否則會破壞用戶的概述?
,其中所有的功能被放置在同一個模塊的一個例子:
override x.OnModelCreating (mb:DbModelBuilder) =
let finished = ignore
let entity = EF.entity<Author> mb
entity
|> EF.hasSeq <@ fun z -> z.Books @>
|> EF.withRequiredProperty <@ fun z -> z.Author @>
|> EF.hasForeignKey <@ fun z -> z.AuthorId @>
|> EF.willCascadeOnDelete true
|> finished