efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Store Types not documented.

Open StuartSpencer-CSIRO opened this issue 1 year ago • 1 comments

The MigrationBuilder.InsertData() method accepts a string[] columnTypes with no description of what the text of the strings must be. The format must be something specific as "String" "System.String" "System.Data.SqlTypes.SqlString" "nvarchar" and "nvarchar(max)" all throw errors...

StuartSpencer-CSIRO avatar Aug 28 '24 00:08 StuartSpencer-CSIRO

@StuartSpencer-CSIRO Data in migrations usually comes from the model, rather than calling these APIs directly. See Data seeding for more information.

ajcvickers avatar Aug 28 '24 09:08 ajcvickers

@StuartSpencer-CSIRO As it says in the documentation it's a "A list of store types for the columns into which data will be inserted.", so something like ["bigint", "nvarchar(max)"] for SQL Server

Share the full call and the exceptions you get.

AndriySvyryd avatar Sep 05 '24 17:09 AndriySvyryd

Have you tried those values @AndriySvyryd? because they did not work for me. The values I found to work was the name (without the namespace) of the SQL Data type. E.g. "SqlString","SqlInt16","SqlBoolean"... I think you may have just proved my point about the doco needing work.

StuartSpencer-CSIRO avatar Sep 05 '24 22:09 StuartSpencer-CSIRO

System.InvalidOperationException: The store type 'int' used for the column 'codes.LAND_USES.lu_level' in a migration data operation is not supported by the current provider.

From: Andriy Svyryd @.> Sent: Friday, 6 September 2024 3:40 AM To: dotnet/efcore @.> Cc: Spencer, Stuart (A&F, Black Mountain) @.>; Mention @.> Subject: Re: [dotnet/efcore] Store Types not documented. (Issue #34549)

@StuartSpencer-CSIROhttps://github.com/StuartSpencer-CSIRO As it says in the documentationhttps://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.migrations.migrationbuilder.insertdata?view=efcore-8.0#microsoft-entityframeworkcore-migrations-migrationbuilder-insertdata(system-string-system-string()-system-string()-system-object(-)-system-string) it's a "A list of store types for the columns into which data will be inserted.", so something like ["bigint", "nvarchar(max)"] for SQL Server

Share the full call and the exceptions you get.

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/efcore/issues/34549#issuecomment-2332299720, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6KDTILNKUI42WMRIY4BGCDZVCJP5AVCNFSM6AAAAABNHESVQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSGI4TSNZSGA. You are receiving this because you were mentioned.Message ID: @.***>

StuartSpencer-CSIRO avatar Sep 05 '24 22:09 StuartSpencer-CSIRO

I am not able to repro this, and we have tests for this like https://github.com/dotnet/efcore/blob/af1047eeae730a37dd0d106c113e3b518132adbc/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsSqlGeneratorTestBase.cs#L219

Please share a minimal runnable project that exhibits this issue.

AndriySvyryd avatar Sep 05 '24 23:09 AndriySvyryd

I don’t know your code at all, and that level is well beyond me. I would however suspect that if you actually run against a physical database, in the order that they are specified, you may see that renaming the “people” table to “person” in the middle would break the rest of the test execution. Also, it is when the actual insert statements are being constructed, not when the migrationBuilder is being added to (i.e. the migrationBuilder.InsertData statement is called) that the exception occurs. All of the SQL is built only as the migrationBuilder seems to fall out of context, i.e. at the end of the migration. Again, I’m not smart enough to know how that impacts your tests. If you confirm that you end up with a physical SQL Server database with data in it, named either “people” or “person”, then I have a small hat here ready to be eaten.

From: Andriy Svyryd @.> Sent: Friday, 6 September 2024 9:26 AM To: dotnet/efcore @.> Cc: Spencer, Stuart (A&F, Black Mountain) @.>; Mention @.> Subject: Re: [dotnet/efcore] Store Types not documented. (Issue #34549)

I am not able to repro this, and we have tests for this like https://github.com/dotnet/efcore/blob/af1047eeae730a37dd0d106c113e3b518132adbc/test/EFCore.Relational.Specification.Tests/Migrations/MigrationsSqlGeneratorTestBase.cs#L219

Please share a minimal runnable project that exhibits this issue.

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/efcore/issues/34549#issuecomment-2332877633, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6KDTILJAL4626JN2B4RTZDZVDSALAVCNFSM6AAAAABNHESVQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSHA3TONRTGM. You are receiving this because you were mentioned.Message ID: @.***>

StuartSpencer-CSIRO avatar Sep 05 '24 23:09 StuartSpencer-CSIRO

Those tests execute code beyond the point where the exception you see would be thrown.

Again, please share a minimal runnable project that exhibits this issue if you want us to investigate this further.

AndriySvyryd avatar Sep 06 '24 00:09 AndriySvyryd