Efcore: HasData not working with 3.0.0-preview6.19304.10 when using Migrations on SQLite

Created on 22 Jun 2019  路  5Comments  路  Source: dotnet/efcore

when using SQLite database
the following configuration works perfectly on 3.0.0-preview5.19227.1
when using Add-Migration
```c#
var p = new Person() { Id = 1, Name = "Test Name",NationalID="1234" };
modelBuilder.Entity().HasData(p);

but fails on `3.0.0-preview6.19304.10` with the following error:
```c#
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
   at lambda_method(Closure , ValueBuffer )
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalMixedEntityEntry..ctor(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer& valueBuffer)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryFactory.NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer& valueBuffer)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.CreateEntry(IDictionary`2 values, IEntityType entityType)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.TrackData(IModel source, IModel target)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IModel source, IModel target, DiffContext diffContext)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to cast object of type 'System.Int32' to type 'System.String'.
closed-fixed type-bug

Most helpful comment

@bigworld12 Thanks--we discussed in triage and we think we know where the issue is.

All 5 comments

@bigworld12 Please post a small, runnable project/solution or complete code listing that demonstrates the behavior you are seeing.

@ajcvickers it's a very minimal model consisting of only one entity (Person) connecting to a SQLite database and a single DBSet

@bigworld12 Thanks--we discussed in triage and we think we know where the issue is.

Verified that this is now fixed in the 3.0 daily builds.

Was this page helpful?
0 / 5 - 0 ratings