我遵循damienbod(https://damienbod.com/2016/01/11/asp-net-5-with-postgresql-and-entity-framework-7/)的指导。我设法连接到我的PostgreSql数据库,并创建EntityMigration历史记录表,DataEventRecord表和SourceInfo表。总共有三个项目(Postgre需要两个,第三个是我的实际项目):DataAccessPostgreSqlProvider,DomainModel和iConnect。使用EF和Dot Net Core 1(PostgreSQL数据库)生成迁移时出错
我创建了一个型号,下面的代码,然后执行:添加迁移NestProtectDevices -Context NestProtectDevices
我必须指定-Context或我得到一个错误,如果我指定的-Context DomainModelPostgreSqlContext,它只是生成一个空的迁移文件(而不是从我的模型中生成一个)。这就是为什么我指定-Context作为Model的名称。以下是模型的代码和我得到的错误。让我知道是否需要其他代码来帮助调试。
using DataAccessPostgreSqlProvider;
using DomainModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using DomainModel.Model;
namespace iConnect.Models.Nest
{
public class NestProtectDevices : DomainModelPostgreSqlContext
{
public NestProtectDevices(DbContextOptions<DomainModelPostgreSqlContext> options) : base(options)
{
}
public long DeviceId { get; set; }
public long UserId { get; set; }
public int CompanyId { get; set; }
public long StructureId { get; set; }
public long WhereId { get; set; }
public string Name { get; set; }
public string NameLong { get; set; }
public bool IsOnline { get; set; }
public int BatteryHealth { get; set; }
public int CoAlarmState { get; set; }
public int SmokeAlarmState { get; set; }
public string UiColorState { get; set; }
public bool IsManualTestActive { get; set; }
public DateTime LastManualTestTime { get; set; }
public DateTime Timestamp { get; set;}
}
}
命令出现错误:
PM> add-migration NestProtectDevices -Context NestProtectDevices
No parameterless constructor was found on 'NestProtectDevices'. Either add a parameterless constructor to 'NestProtectDevices' or add an implementation of 'IDbContextFactory<NestProtectDevices>' in the same assembly as 'NestProtectDevices'.
不是那个错误告诉你到底是什么问题? –
如果我使它成为一个无参数的构造函数,那么它会出错,它需要提供选项。 – Ronny
我仍然在寻找这方面的答案。 – Ronny