You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Batching through a table variable may not work for non-default collations #7172
I have a database with some columns collations set to be case sensitive. Now EF build its query with a temp table, but this temp table does not have the collation on the column so on the insert the database server throws an exception.
Until there is a work-around i can not use ef because the regarding columns contain (case sensitive) guids.
I think @seriouz meant to say SaveChanges() fails, as opposed to querying data.
A possible workaround is to disable batching in either the OnConfiguring() method on the DbContext class or on the AddDbContext() method in Startup:
@divega you are right. I create multiple parent and child entities. Which reference each other with case-sensitive guid keys. (something like Pk8hUi....) All of them are added by _dbContext.Add(). And then saved in one chuck with _dbContext.SaveChanges().
In the debug output i can see this line from the query generated by ef: DECLARE @inserted0 TABLE ([FieldGuid] nvarchar(22), [_Position] [int]); the ef query builder misses to check the collation of the underlying column which has a COLLATE SQL_Latin1_General_CP1_CS_AS resulting in a collation missmatch thrown by the mssql server.
Activity
seriouz commentedon Dec 1, 2016
@divega you are right. I create multiple parent and child entities. Which reference each other with case-sensitive guid keys. (something like Pk8hUi....) All of them are added by
_dbContext.Add(). And then saved in one chuck with_dbContext.SaveChanges().In the debug output i can see this line from the query generated by ef:
DECLARE @inserted0 TABLE ([FieldGuid] nvarchar(22), [_Position] [int]);the ef query builder misses to check the collation of the underlying column which has aCOLLATE SQL_Latin1_General_CP1_CS_ASresulting in a collation missmatch thrown by the mssql server.divega commentedon Dec 1, 2016
@seriouz thanks for confirming. Please let me know if the suggested workaround helps.
AndriySvyryd commentedon Jun 9, 2017
We would need to add the ability of specifying collation for a given column to be able to use it in the update pipeline.
AndriySvyryd commentedon Jun 9, 2017
@seriouz As a workaround you can specify the collation as part of the store type:
10 remaining items
Consider non-default column collation in table variable
david-wimmer commentedon Nov 9, 2022
I created a PR #29518 with a proposed fix to this issue.
angularsen commentedon Dec 9, 2022
Workaround: Save one parent entity at a time. It correctly saves related data in its properties.
I didn't see this workaround mentioned anywhere, but it was very helpful for us.
AndriySvyryd commentedon Feb 5, 2024
Depends on #32546 and #29620