c# - “无法将'ConcreteTypeMapping'类型的对象转换为在macos上键入'Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping”WebApi
问题描述
我已按照说明使用 Visual Studio 在 mac os 中创建 WebAPI。
https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api-mac?view=aspnetcore-2.1 https://github.com/aspnet/Docs/blob/master/aspnetcore /tutorials/first-web-api-mac.md
启动.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IAdminUOW, AdminUOW>();
services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>));
services.AddDbContext<MeroRentalContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
sqlServerOption => sqlServerOption.MigrationsAssembly("Database"))
);
services.AddMvc();
}
MeroRentalContext.cs
数据库上下文cs文件
public class MeroRentalContext : DbContext
{
public MeroRentalContext(DbContextOptions<MeroRentalContext> options)
: base(options)
{ }
public DbSet<AdminUser> TodoItems { get; set; }
}
AdminUser.cs 文件
public class AdminUser
{
public Guid UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public DateTime CreatedTimeStamp { get; set; }
public DateTime? ModifiedTimeStamp { get; set; }
public DateTime? LogDate { get; set; }
public short? LogNumber { get; set; }
public bool ReloadActiveFlag { get; set; }
public bool isActive { get; set; }
public string ExtraText { get; set; }
public string ResetPasswordToken { get; set; }
public DateTime? ResetPasswordTokenCreatedTimeStamp { get; set; }
}
通用类到类 db 数据
public class GenericRepository<T> : IGenericRepository<T> where T : class
{
private readonly MeroRentalContext _entities;
public GenericRepository(MeroRentalContext dbContext)
{
_entities = dbContext;
}
public virtual IQueryable<T> GetAll()
{
IQueryable<T> query = _entities.Set<T>();
return query;
}
public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
{
IQueryable<T> query = _entities.Set<T>().Where(predicate);
return query;
}
}
数据库中的表
CREATE TABLE dbo.AdminUser (
UserId uniqueidentifier NOT NULL,
FirstName varchar(max) NOT NULL,
LastName varchar(max) NOT NULL,
Email varchar(max) NOT NULL,
UserName varchar(max) NOT NULL,
Password varchar(max) NOT NULL,
CreatedTimeStamp datetime NOT NULL DEFAULT (getdate()),
ModifiedTimeStamp datetime NULL,
LogDate datetime NULL,
LogNumber smallint NULL,
ReloadActiveFlag bit NOT NULL DEFAULT ((0)),
isActive bit NOT NULL DEFAULT ((1)),
ExtraText varchar(max) NULL,
ResetPasswordToken varchar(max) NULL,
ResetPasswordTokenCreatedTimeStamp datetime NULL
);
ALTER TABLE dbo.AdminUser ADD CONSTRAINT PK__AdminUse__1788CC4C305F59E9 PRIMARY KEY (UserId);
因为在调试时出现错误
无法将“ConcreteTypeMapping”类型的对象转换为“Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping”
做了一些研究但找不到解决方案 https://github.com/aspnet/EntityFrameworkCore/issues/8369 https://github.com/aspnet/EntityFrameworkCore/issues/11704 https://www.ctolib.com/文章/评论/61636
解决方案
根据https://github.com/aspnet/EntityFrameworkCore/issues/11704,您的版本不匹配。
您的一些实体框架版本正在引用2.1
,而另一些正在引用2.0
.
您需要将它们全部更改为参考版本2.1
。
您应该打开所有csproj
文件并搜索2.0
和2.1
。
推荐阅读
- javascript - 当用户滚动到达锚元素时触发事件
- java - 了解 OpenGL 基础知识
- java - JCombobox 不能在 jar 上工作
- java - Mockito 没有返回我需要的东西
- c++ - C++17 标准库包括不使用 Visual Studio 2017 中的 Android 项目
- powershell - 如何制作 PowerShell FTPS 脚本 (SSL) 来上传单个文件?
- java - 如何以编程方式表示阶乘
- algorithm - 在更改标志之间处理系统重启/崩溃
- c++ - dyld:使用 VTK 运行 C++ 项目时找不到符号 _PyBaseObject_Type
- docker - 在 OS (CoreOS) 重启 Docker 启动多个容器