question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Batching through a table variable may not work for non-default collations

See original GitHub issue

(copied from @seriouz’s comment at https://github.com/aspnet/EntityFramework/issues/6577#issuecomment-264244982)

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:

    optionsBuilder => optionsBuilder
        .UseSqlServer(connectionString)
        .MaxBatchSize(1);

cc @AndriySvyryd as FYI

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AndriySvyrydcommented, Jun 9, 2017

@seriouz As a workaround you can specify the collation as part of the store type:

.Property(e => e.FieldGuid).HasColumnType("nvarchar(22) COLLATE SQL_Latin1_General_CP1_CS_AS");
0reactions
angularsencommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Table Variable in SQL Server
The reason for this case is, the first INFORMATION_SCHEMA. COLUMNS view, and table variable executed in the same batch so we can get...
Read more >
Azure SQL database table variable collation
Try using. DECLARE @resultingRoles TABLE ([MemberRoleName] NVARCHAR(256) COLLATE Latin1_General_CI_AS NOT NULL PRIMARY KEY).
Read more >
Table Variable and Database Scope
Table variables have the scope of the batch or stored procedure they are run in. There is no need to drop the table...
Read more >
T-SQL Table variable with case sensitive columns - collate ...
The reason I want to do this is because I have case sensitive information in my source table but when I insert it...
Read more >
Best practices with Amazon Aurora MySQL
This topic includes information on best practices and options for using or migrating data to an Amazon Aurora MySQL DB cluster.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found