F# ASP.net MVC 项目无法在 VS 2019 中编译
F# ASP.net MVC Project won't compile in VS 2019
我一直在重温我的一个旧实验。下面的代码是我添加到 Daniel Mohl's F# MVC5 project 的文件,我在 Visual Studio 2015 年创建了它。它在 VS2015 中编译和工作(现在仍然如此)但是当我尝试在 VS2019 中编译它时,我收到一条错误消息在接近尾声的 |> this.View
行:“FS0405:调用了一个受保护的成员或正在使用 'base'。这只允许在成员的直接实现中使用,因为它们可以逃脱其对象范围”。有谁知道我需要做什么来消除错误
namespace fsmvcproject.Models
open System
open System.ComponentModel.DataAnnotations
type Newarticle() =
[<Key>]member val Id = 0 with get, set
member val Headline = "" with get, set
member val Author = "" with get, set
member val Publication = "" with get, set
member val Intro = "" with get, set
member val Story = "" with get, set
namespace fsmvcproject.Repositories
open System.Data.Entity
open fsmvcproject.Models
open System.Collections.Generic
type SGdbEntities() =
inherit DbContext("Data Source=127.0.0.1\SQLEXPRESS;Persist Security Info=True;Initial Catalog=SG;User ID=xxxx;Password=xxxx")
[<DefaultValue()>] val mutable newarticles : IDbSet<Newarticle>
member x.Newarticles with get() = x.newarticles and set v = x.newarticles <- v
type NewarticlesRepository() =
member x.GetAll () =
use context = new SGdbEntities()
query { for a in context.Newarticles do
sortByDescending a.Id
select a }
|> Seq.toList
member x.GetDetail (id) =
use context = new SGdbEntities()
query { for a in context.Newarticles do
where (a.Id = id)
select a }
|> Seq.toList
namespace fsmvcproject.Controllers
open fsmvcproject.Repositories
open System.Web.Mvc
[<HandleError>]
type ArticlesController(repository :NewarticlesRepository) =
inherit Controller()
new() = new ArticlesController(NewarticlesRepository())
member this.Index () =
repository.GetAll()
|> this.View
member this.Detail (id) =
repository.GetDetail(id)
|> this.View
我认为这里的问题在于 View
是一个受保护的方法,这意味着您可以直接从派生的 class 中调用它,但您不能将其视为第一个- class F# 函数。
因此,要修复编译器错误,请尝试将 model |> this.View
更改为 this.View(model)
。
我一直在重温我的一个旧实验。下面的代码是我添加到 Daniel Mohl's F# MVC5 project 的文件,我在 Visual Studio 2015 年创建了它。它在 VS2015 中编译和工作(现在仍然如此)但是当我尝试在 VS2019 中编译它时,我收到一条错误消息在接近尾声的 |> this.View
行:“FS0405:调用了一个受保护的成员或正在使用 'base'。这只允许在成员的直接实现中使用,因为它们可以逃脱其对象范围”。有谁知道我需要做什么来消除错误
namespace fsmvcproject.Models
open System
open System.ComponentModel.DataAnnotations
type Newarticle() =
[<Key>]member val Id = 0 with get, set
member val Headline = "" with get, set
member val Author = "" with get, set
member val Publication = "" with get, set
member val Intro = "" with get, set
member val Story = "" with get, set
namespace fsmvcproject.Repositories
open System.Data.Entity
open fsmvcproject.Models
open System.Collections.Generic
type SGdbEntities() =
inherit DbContext("Data Source=127.0.0.1\SQLEXPRESS;Persist Security Info=True;Initial Catalog=SG;User ID=xxxx;Password=xxxx")
[<DefaultValue()>] val mutable newarticles : IDbSet<Newarticle>
member x.Newarticles with get() = x.newarticles and set v = x.newarticles <- v
type NewarticlesRepository() =
member x.GetAll () =
use context = new SGdbEntities()
query { for a in context.Newarticles do
sortByDescending a.Id
select a }
|> Seq.toList
member x.GetDetail (id) =
use context = new SGdbEntities()
query { for a in context.Newarticles do
where (a.Id = id)
select a }
|> Seq.toList
namespace fsmvcproject.Controllers
open fsmvcproject.Repositories
open System.Web.Mvc
[<HandleError>]
type ArticlesController(repository :NewarticlesRepository) =
inherit Controller()
new() = new ArticlesController(NewarticlesRepository())
member this.Index () =
repository.GetAll()
|> this.View
member this.Detail (id) =
repository.GetDetail(id)
|> this.View
我认为这里的问题在于 View
是一个受保护的方法,这意味着您可以直接从派生的 class 中调用它,但您不能将其视为第一个- class F# 函数。
因此,要修复编译器错误,请尝试将 model |> this.View
更改为 this.View(model)
。