Я пытаюсь запустить тестовый проект с использованием MySQL и EF6, используя Visual Studio 2019 Community Preview для Mac.В качестве отправной точки я использую шаблон Web Application (Model-View-Controller)
/ .NET Core -> App
, а также базу данных MyWind .Я получаю следующее исключение и не знаю, как действовать.
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 --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
яя получаю следующее предупреждение:
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
напрямую для извлечения данных из базы данных.