我在这里按照EntityFrameworkCore教程 https://docs.efproject.net/en/staging/platforms/aspnetcore/new-db.html 但是当我到达教程的创建数据库部分 https://docs.efproject .net/en/staging/platforms/aspnetcore/new-db.html #create-your-database 并运行命令Add-Migration MyFirstMigration我收到以下错误:
Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.
Run Code Online (Sandbox Code Playgroud)
我尝试安装Microsoft.EntityFrameworkCore.Design以及Microsoft.EntityFrameworkCore.SqlServer.Design NuGet上的每个版本但仍然得到相同的错误.
我还尝试使用该命令在NuGet PM之外运行
并得到以下错误:
Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Run Code Online (Sandbox Code Playgroud)
我尝试了所有我能想到的东西,并在互联网上到处寻找,但仍然没有找到答案.
c# entity-framework visual-studio nuget entity-framework-core
我有两种类型,它们共享一个命名值.
type Type1 =
{
p1: int;
p2: int;
}
type Type2 =
{
p1 : int;
p3 : int;
}
Run Code Online (Sandbox Code Playgroud)
是否可以创建仅更改此命名值(p1)并返回新记录的函数?
我试过这么远:
type IType =
abstract member p1: int;
type Type1 =
{
p1: int;
p2: int;
}
interface IType with
member this.p1 = this.p1
type Type2 =
{
p1 : int;
p3 : int;
}
interface IType with
member this.p1 = this.p1
let changeP1ToTen (value: 'a when 'a :> IType) =
let newValue = {value with p1 = …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用F#,我的大脑已经破碎,试图弄清楚如何使用它的类型,而不必采用OO类型的编程.
这是我的情况我基本上想要创建一个方法,我提供类型和Id,它返回给我数据库中的对象.
所以基本上这就是我到目前为止所得到的.
let client = MongoClient()
let database = client.GetDatabase("testdb")
let lowerCase (str : string) =
str.ToLower()
let nameOf (classType: Type) =
classType.Name
let nameTypeOf<'a> =
nameOf typeof<'a>
let getCollection<'a> =
let collectionName = nameTypeOf<'a> |> lowerCase
database.GetCollection<'a> collectionName
let dbSelect<'a> id =
let collection = getCollection<'a>
collection.Find(fun(x) -> x.Id = id).First()
Run Code Online (Sandbox Code Playgroud)
所以我的问题是使用dbSelect,显然它不编译,因为x是通用的,基本上我想创建一个带有Id的接口,所有我的对象都与它接口.我知道如何使用类和继承来实现它,但我避免在cop库之外使用实例化的类.如果有的话,最好的功能方法是什么.
这就是我所期待的
type IDbObject =
abstract Id: string
type Item =
{
Id: string
Name: string
}
interface IDbObject with
member x.Id = x.Id
let item = …Run Code Online (Sandbox Code Playgroud) 所以我有一个简单的对象
type DbObject() =
member val Id = ObjectId.GenerateNewId().ToString() with get, set
member val Name = "" with get, set
type Item() =
inherit DbObject()
member val Description = "" with get, set
member val Refs : list<string> = [] with get, set
Run Code Online (Sandbox Code Playgroud)
当我将它插入到我的 MongoDB 数据库中时,这工作得很好,但是每当我尝试接收它时,我都会收到以下错误。
System.FormatException: An error occurred while deserializing the Material property of class Item: Type 'Microsoft.FSharp.Collections.FSharpList`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' does not have a suitable constructor or Add method. ---> MongoDB.Bson.BsonSerializationException: Type 'Microsoft.FSharp.Collections.FSharpList`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, …Run Code Online (Sandbox Code Playgroud)