Cannot Migrate/Load table with Discriminator.
Cannot Migrate/Load table with Discriminator.
Now testing migrate to EntityFrameworkCore but...
1. Cannot migrate/generate table with Discriminator
2. Cannot load elements even if database exitsts.
Currently using dotConnect for SQLite v5.6.714 with EntityFrameworkCore 1.0.0.
---sample---
class Program
{
static void Main(string[] args)
{
{
DbContextOptionsBuilder builderDa = new DbContextOptionsBuilder();
builderDa.UseSQLite("DataSource = .test.db");
// builderDa.UseSqlite("DataSource = .test.db");
Context context = new Context(builderDa.Options);
context.Database.Migrate(); /* 1. Cannot migrate/generate database... */
//
context.Add(new EntityExt() { ExtData = "data" });
context.SampleEntity.Add(new EntityExt() { ExtData = "data2" });
context.SaveChanges();
//
context.SampleEntity.Load(); /* 2. Cannot load elements even if database exitsts ... */
}
}
}
public class Context : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EntityBase>()
.HasDiscriminator()
.HasValue<EntityBase>("base")
.HasValue<EntityExt>("ext")
;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if( !optionsBuilder.IsConfigured)
{
// optionsBuilder.UseSQLite("DataSource=.test.db");
optionsBuilder.UseSqlite("DataSource=.test.db"); /* can generate, but not supports encryption... */
}
}
public Context()
{
}
public Context(DbContextOptions options)
: base(options)
{
}
public DbSet<EntityBase> SampleEntity { get; set; }
}
[Table("EntityBase")]
public class EntityBase
{
[Key]
public int Id { get; set; }
}
public class EntityExt : EntityBase
{
public string ExtData { get; set; }
}
1. Cannot migrate/generate table with Discriminator
2. Cannot load elements even if database exitsts.
Currently using dotConnect for SQLite v5.6.714 with EntityFrameworkCore 1.0.0.
---sample---
class Program
{
static void Main(string[] args)
{
{
DbContextOptionsBuilder builderDa = new DbContextOptionsBuilder();
builderDa.UseSQLite("DataSource = .test.db");
// builderDa.UseSqlite("DataSource = .test.db");
Context context = new Context(builderDa.Options);
context.Database.Migrate(); /* 1. Cannot migrate/generate database... */
//
context.Add(new EntityExt() { ExtData = "data" });
context.SampleEntity.Add(new EntityExt() { ExtData = "data2" });
context.SaveChanges();
//
context.SampleEntity.Load(); /* 2. Cannot load elements even if database exitsts ... */
}
}
}
public class Context : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EntityBase>()
.HasDiscriminator()
.HasValue<EntityBase>("base")
.HasValue<EntityExt>("ext")
;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if( !optionsBuilder.IsConfigured)
{
// optionsBuilder.UseSQLite("DataSource=.test.db");
optionsBuilder.UseSqlite("DataSource=.test.db"); /* can generate, but not supports encryption... */
}
}
public Context()
{
}
public Context(DbContextOptions options)
: base(options)
{
}
public DbSet<EntityBase> SampleEntity { get; set; }
}
[Table("EntityBase")]
public class EntityBase
{
[Key]
public int Id { get; set; }
}
public class EntityExt : EntityBase
{
public string ExtData { get; set; }
}
Re: Cannot Migrate/Load table with Discriminator.
Thank you for your report. We will investigate the issues and notify you about the result.
Re: Cannot Migrate/Load table with Discriminator.
This is a designed behaviour caused by EF Core engine, a standard provider (System.Data.SqlClient) throws a similar error:
Workaround (via code-based Code-First Migrations):
1. [via Nuget Package Manager Console]
> Install-Package Microsoft.EntityFrameworkCore.SqlServer
2. > Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
3. > add-migration first
4. > update-database
The current public build of dotConnect for SQLite throws System.NullReferenceException when using TPH inheritance in EF Core. The bug is fixed. Look forward to the new public build of dotConnect for SQLite. We will notify you when it is available for download.
Code: Select all
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Additional information: Invalid object name 'EntityBase'.
1. [via Nuget Package Manager Console]
> Install-Package Microsoft.EntityFrameworkCore.SqlServer
2. > Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
3. > add-migration first
4. > update-database
The current public build of dotConnect for SQLite throws System.NullReferenceException when using TPH inheritance in EF Core. The bug is fixed. Look forward to the new public build of dotConnect for SQLite. We will notify you when it is available for download.
Re: Cannot Migrate/Load table with Discriminator.
New build of dotConnect for SQLite 5.6.729 is available for download now: viewtopic.php?f=29&t=34213.
Re: Cannot Migrate/Load table with Discriminator.
I tried dotConnect SQLite 5.6.729 .
Migrate method and update-database completed, but can't load any TPH entities.
Migrate method and update-database completed, but can't load any TPH entities.
Re: Cannot Migrate/Load table with Discriminator.
We have reproduced the issue with the following queries:
We will notify you when it is fixed.
As a workaround, please use:
Code: Select all
context.SampleEntity.Load();
var all_results = context.SampleEntity.ToList();
var EntityBase_results = context.SampleEntity.OfType<EntityBase>().ToList();
As a workaround, please use:
Code: Select all
var EntityExt_results = context.SampleEntity.OfType<EntityExt>().ToList();
Re: Cannot Migrate/Load table with Discriminator.
The newest (5.6.743) build of dotConnect for SQLite includes the corresponding fixes:
- The bug with processing IN expressions in EF Core is fixed
- The bug with retrieving objects of TPH hierarchy in EF Core is fixed