问题描述
我正在尝试使用适用于Mac的Visual Studio 2019社区预览版使用MySQL和EF6运行测试项目.我正在使用Web Application (Model-View-Controller)
/.NET Core -> App
模板以及 MyWind 数据库作为起点.我收到以下异常,并且不确定如何继续.
I'm trying to get a test project running using MySQL and EF6 using Visual Studio 2019 Community Preview for Mac. I am using the Web Application (Model-View-Controller)
/ .NET Core -> App
template as a starting point as well as the MyWind database. I'm getting the following exception and am not sure how to proceed.
TypeLoadException: Could not load type 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
System.Data.Entity.ModelConfiguration.Utilities.AttributeProvider.GetTypeDescriptor(Type type)
System.Data.Entity.ModelConfiguration.Utilities.AttributeProvider.GetAttributes(Type type)
System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
System.Data.Entity.Internal.RetryLazy<TInput, TResult>.GetValue(TInput input)
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
System.Data.Entity.Internal.InternalContext.Initialize()
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
System.Data.Entity.Internal.Linq.InternalSet<TEntity>.Initialize()
System.Data.Entity.Internal.Linq.InternalSet<TEntity>.get_InternalContext()
System.Data.Entity.Infrastructure.DbQuery<TResult>.System.Linq.IQueryable.get_Provider()
System.Linq.Queryable.OrderBy<TSource, TKey>(IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
Ef2MySql.Controllers.HomeController.Contact() in HomeController.cs ViewData["Customers"] = db.Customers.OrderBy(c => c.company).ThenBy(c => c.last_name).ThenBy(c => c.first_name).Take(10);
lambda_method(Closure , object , object[] )
Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
这是我的相关代码.
HomeController.cs
namespace Ef2MySql.Controllers
{
public class HomeController : Controller
{
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
using (var db = new NorthwindContext())
{
ViewData["Customers"] = db.Customers.OrderBy(c => c.company).ThenBy(c => c.last_name).ThenBy(c => c.first_name).Take(10);
}
return View();
}
}
}
NorthwindContext.cs
namespace Ef2MySql.Database
{
public partial class NorthwindContext : DbContext
{
public NorthwindContext() : base("Server=localhost;Database=northwind;Uid=northwind;Pwd=northwind;")
{
}
public virtual DbSet<Customer> Customers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}
NorthwindMysqlConfiguration.cs
namespace Ef2MySql.Database
{
public class NorthwindMysqlConfiguration : MySqlEFConfiguration
{
public NorthwindMysqlConfiguration()
{
}
}
}
Customer.cs
namespace Ef2MySql.DomainObjects
{
public class Customer
{
public Customer()
{
}
public String id { get; set; }
public String company { get; set; }
public String last_name { get; set; }
public String first_name { get; set; }
public String email_address { get; set; }
public String job_title { get; set; }
public String business_phone { get; set; }
public String home_phone { get; set; }
public String mobile_phone { get; set; }
public String fax_number { get; set; }
public String address { get; set; }
public String city { get; set; }
public String state_province { get; set; }
public String zip_postal_code { get; set; }
public String country_region { get; set; }
public String web_page { get; set; }
public String notes { get; set; }
}
}
这是我正在使用的mono版本.
Here's the version of mono I'm using.
$ mono --version
Mono JIT compiler version 5.18.0.248 (2018-08/a4956c837e1 Fri Jan 25 16:13:12 EST 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:
SIGSEGV: altstack
Notification: kqueue
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: yes(600)
Suspend: preemptive
GC: sgen (concurrent by default)
我不确定这是否相关,但是对于MySql.Data.Entity
和EntityFramework
软件包,我收到以下警告:
I'm not sure if this is relevant, but for the MySql.Data.Entity
and EntityFramework
packages, I'm getting the following warning:
Package 'EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.
对于它的价值,我能够直接使用MySql.Data.MySqlClient.MySqlConnection
从数据库中检索数据.
For what it's worth, I am able to use MySql.Data.MySqlClient.MySqlConnection
directly to retrieve data from the database.
推荐答案
进行了一些研究后,看来该类只是失去了corefx . 已在3.0中添加.
After doing some research, it seems that this class is simply missing from corefx. It has been added for 3.0.
这篇关于尝试使用Mysql.Data.Entity时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!