我按照此链接中的说明进行操作
https://dev.mysql.com/doc/dev/connector-net/html/connector-net-x-devapi-reference.htm
如下所示。 (Program.cs文件)
using MySql.XDevAPI;
using MySql.XDevAPI.Common;
using MySql.XDevAPI.CRUD;
using System;
using Microsoft.EntityFrameworkCore;
namespace consoleApp
{
public class Program
{
public static void Main(string[] args)
{
// string schemaName = "world_x";
string schemaName = "sakila";
string connectionString = "server=localhost;port=3306;uid=username;password=";
Session session = MySQLX.GetSession(connectionString);
Schema schema = session.GetSchema(schemaName);
// Use the collection 'customer'
var myCollection = schema.GetCollection("customer");
var docParams = new DbDoc(new { name1 = "MARY", _id1 = "1" });
// Find a document
DocResult foundDocs = myCollection.Find("first_name = :name1|| store_id = :_id1").Bind(docParams).Execute();
while (foundDocs.Next())
{
Console.WriteLine(foundDocs.Current["Name"]);
Console.WriteLine(foundDocs.Current["_id"]);
}
}
}
}
还有ConsoleApp.csproj文件
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.3.0" />
<PackageReference Include="MySql.Data" Version="8.0.8-dmr" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.8-dmr" />
<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.8-dmr" />
</ItemGroup>
</Project>
appsettings.json文件
{
"ConnectionStrings":
{
"SampleConnection": "server=localhost;userid=username;pwd=;port=3306;database=sakila;sslmode=none;"
}
}
首先使用简单的控制台应用程序而不是网络来简化错误
但毕竟我不断收到以下错误
=============================================== ======================
dotnet build
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(1,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
Program.cs(2,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
Program.cs(3,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
Build FAILED.
Program.cs(1,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
Program.cs(2,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
Program.cs(3,13): error CS0234: The type or namespace name 'XDevAPI' does not exist in the namespace 'MySql' (are you missing an assembly reference?) [/home/filePath/consoleApp/consoleApp.csproj]
0 Warning(s)
3 Error(s)
Time Elapsed 00:00:02.00
=============================================== ======================
我有什么遗失或者我没有安装或者什么? ! 我真的需要帮助来弄清楚出了什么问题。 谢谢!