Код: Выделить всё
public class CodebookContext : DefaultDatabaseContext
{
public DbSet AssetGroup { get; set; } = null!;
public CodebookContext(): base() { }
public CodebookContext(DbContextOptions dbContextOptions)
: base(dbContextOptions) { }
protected override IModel OptimizedLoaderInstance()
{
return CodebookContextModel.Instance;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity(entity => { });
}
}
public abstract class DefaultDatabaseContext : DbContext
{
public DefaultDatabaseContext () : base() { }
public DatabaseConnectionContext(DbContextOptions options) : base(options) { }
protected abstract IModel OptimizedLoaderInstance();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder
.UseModel(OptimizedLoaderInstance())
.UseSqlServer(
"Server=myservername; Database=mydbname; User ID=mydbusername; Password=mydbuserpassword; Trusted_Connection=False; TrustServerCertificate=True;",
o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery)
);
}
}
}
antity assetgroup определяется следующим образом:
Код: Выделить всё
[Table(nameof(AssetGroup), Schema = "test")]
public class AssetGroup : CoreDbEntity
{
[Required]
[MaxLength(255)]
public string Name { get; set; } = string.Empty;
[MaxLength(255)]
public string? Type { get; set; }
public override string ToString()
{
return base.ToString();
}
}
public abstract class CoreDbEntity : ICoreDbEntity
{
[Key]
[Required]
public virtual TKey? ID { get; set; }
public override string ToString()
{
return base.ToString() + ID!.ToString();
}
}
< /code>
Когда я пытаюсь запустить команду: < /p>
dotnet ef migrations add Codebook.InitialV1 --context CodebookContext -o ./Migrations/Codebook --verbose
Подробнее здесь: https://stackoverflow.com/questions/796 ... -completes
Мобильная версия