我一直在重温我以前的一个实验。下面的代码是我添加到Daniel Mohl的f# MVC5项目中的文件,该项目是我在Visual Studio 2015中创建的。它在VS2015中编译和工作(并且仍然如此),但当我尝试在VS2019中编译它时,我在末尾的|> this.View
行上得到一个错误消息:"FS0405:一个受保护的成员被称为或"基础"正在使用。这只允许在成员的直接实现中,因为它们可以转义其对象作用域。有没有人知道我需要做些什么来消除错误
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.1SQLEXPRESS;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
是一个受保护的方法,这意味着你可以直接从你的派生类调用它,但你不能把它当作一级f#函数。
因此,要修复编译错误,请尝试将model |> this.View
更改为this.View(model)
。