【发布时间】:2016-10-26 14:12:04
【问题描述】:
由于 MySQL DB 提供程序已经发布(“预发布”),我正在将我的 ASP.NET Core 项目从使用 Microsoft SQL Server 迁移到 MySQL。我在使用 SQL Server 时使用 Core Identity 作为成员资格,它在该配置中工作。当我将数据库迁移到 MySQL 时(使用 MySQL Workbench 中的迁移向导),我在将新用户保存到数据库时开始收到此错误:
找不到 CLR 类型“Microsoft.EntityFrameworkCore.Metadata.Internal.Property”的关系类型的映射
执行 CreateAsync 方法时,此代码中出现错误:
public IActionResult Register([FromBody]RegisterViewModel obj)
{
if (ModelState.IsValid)
{
IdentityUser user = new IdentityUser();
user.UserName = obj.Username;
user.Email = obj.Email;
IdentityResult result = _userManager.CreateAsync(user, obj.Password).Result;
}
}
这是我的 DbContext 类:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace PilotMaltApiCore.Models
{
public class PilotDbContext : IdentityDbContext<IdentityUser, IdentityRole, string>
{
public PilotDbContext(DbContextOptions<PilotDbContext> options)
: base(options)
{
//nothing here
}
public DbSet<Batch> Batches { get; set; }
public DbSet<Bag> Bags { get; set; }
public DbSet<Vendor> Vendors { get; set; }
public DbSet<Variety> Varieties { get; set; }
}
}
我认为这可能与 SQL Server 和 MySQL 之间的数据类型差异有关。这是 SQL Server 表:
这是在 MySQL Workbench 中使用迁移向导后的 MySQL 表:
请记住,所有代码在使用 SQL Server 时都能正常工作。感谢您的帮助,谢谢!
【问题讨论】:
标签: mysql asp.net sql-server asp.net-core asp.net-identity