Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework F#-合并模块?_Entity Framework_F#_Ef Code First - Fatal编程技术网

Entity framework F#-合并模块?

Entity framework F#-合并模块?,entity-framework,f#,ef-code-first,Entity Framework,F#,Ef Code First,我目前正在为F#编写一个实体框架代码第一包装器,我一直在想是否应该将所有模块合并成一个 看看这个: module ManyNavProperty = let withMany (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithMany() let withSeq expr (cfg:ManyNavPropertyInfo<'a,'b>) = cfg.WithSeq expr let withList expr (

我目前正在为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
模块ManyNavProperty=
让withMany(cfg:ManyNavPropertyInfo)=cfg.withMany()
设withSeq expr(cfg:ManyNavPropertyInfo)=cfg.withSeq expr
让withList expr(cfg:ManyNavPropertyInfo)=cfg.withList expr
让withArray expr(cfg:ManyNavPropertyInfo)=cfg.withArray expr
let withOptional(cfg:ManyNavPropertyInfo)=cfg.withOptional()
let withOptionalProperty表达式(cfg:ManyNavPropertyInfo)=cfg.WithOptionalExpr
let withRequired(cfg:ManyNavPropertyInfo)=cfg.withRequired()
let withRequiredProperty expr(cfg:ManyNavPropertyInfo)=cfg.withRequiredProperty expr
模块DependentNavProperty=
让hasForeignKey expr(cfg:DependentNavPropertyInfo(cfg.Entity)=cfg.HasKey expr
让hasSeq expr(cfg:EntityInfo)=cfg.HasList expr
让hasArray expr(cfg:EntityInfo)=cfg.hasaoptional expr
让hasRequired expr(cfg:EntityInfo)=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
重写x.OnModelCreating(mb:DbModelBuilder)=
让完成=忽略
让实体=EF.entity mb
实体
|>EF.hasSeq z.图书@>
|>ManyNavProperty.withRequiredProperty z.作者@>
|>DependentNavProperty.hasForeignKey z.AuthorId@>
|>CascadableNavProperty.willCascadeOnDelete true
|>完成
这么多模块的使用会让用户感到困惑吗?-我应该将它们全部放在一个模块中,还是会破坏用户的总体印象

将所有函数放置在同一模块中的示例:

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
重写x.OnModelCreating(mb:DbModelBuilder)=
让完成=忽略
让实体=EF.entity mb
实体
|>EF.hasSeq z.图书@>
|>EF.withRequiredProperty z.作者@>
|>EF.hasForeignKey z.AuthorId@>
|>EF.willCascadeOnDelete true
|>完成

这是一个棘手的设计问题

通常,F#库倾向于将使用类型(例如
list
seq
)的函数分组到一个单独的模块中,该模块的名称与类型(例如
list.xyz
seq.xyz
)相同。这对于常见类型很有效,因为用户学会了如何查找函数

但是,对于不太常见的类型(例如,您自己的库),发现这些模块可能有点困难(特别是如果类型不是显式创建的(而是通过一些调用获得的)。拥有一个模块名,然后使用
来探索它是非常强大的

我可能会建议使用嵌套模块。类似于:

module EF =
  // common functions
  module Cascadable = 
    // CascadableNavProperty functions
  module Many = 
    // etc.
entity
|> EF.hasSeq <@ fun z -> z.Books @>
  |> EF.Many.withRequiredProperty <@ fun z -> z.Author @>
    |> EF.Dependent.hasForeignKey <@ fun z -> z.AuthorId @>
      |> EF.Cascadable.willCascadeOnDelete true
|> finished
然后,用户可以从
EF
开始查找所有内容

module EF =
  // common functions
  module Cascadable = 
    // CascadableNavProperty functions
  module Many = 
    // etc.
entity
|> EF.hasSeq <@ fun z -> z.Books @>
  |> EF.Many.withRequiredProperty <@ fun z -> z.Author @>
    |> EF.Dependent.hasForeignKey <@ fun z -> z.AuthorId @>
      |> EF.Cascadable.willCascadeOnDelete true
|> finished
实体
|>EF.hasSeq z.图书@>
|>EF.Many.WITHREQUIRED PROPERTY z.作者@>
|>EF.Dependent.hasForeignKey z.authord@>
|>EF.Cascadable.willCascadeOnDelete true
|>完成