efcore: Can not use Entity Framework Core 3.1 when set ENV LC_ALL and LANG in docker container
Now i use efcore v 3.1.7 in dotnet core TargetFramework netcoreapp3.1 I try to add this 2 line below into my docker file
ENV LANG th_TH.UTF-8
ENV LANGUAGE th_TH:th
These 2 line of config make my report can generate correctly language in dotnetcore v 2.1 With lib ReportServer ( Microsoft.VisualStudio.ConnectedService.Wcf v15.0.40203.910)
But when i migrate to dotnetcore 3.1 and set that 2 env it make i can not query entity framework core 3.1.7 with this code
var userLogedIn = await _uow.User.Where(w => w.empNo == dataEmpNo).AsNoTracking().FirstOrDefaultAsync();
It alway show error message like this
{
"ex": {
"ClassName": "Microsoft.Data.SqlClient.SqlException",
"Message": "Invalid column name '__dataEmpNo_0'.",
"Data": {
"HelpLink.ProdName": "Microsoft SQL Server",
"HelpLink.ProdVer": "14.00.1000",
"HelpLink.EvtSrc": "MSSQLServer",
"HelpLink.EvtID": "207",
"HelpLink.BaseHelpUrl": "http://go.microsoft.com/fwlink",
"HelpLink.LinkId": "20476",
"SqlError 1": "Microsoft.Data.SqlClient.SqlError: Invalid column name '__dataEmpNo_0'."
},
"InnerException": null,
"HelpURL": null,
"StackTraceString": " at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task`1 result)\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()\n at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)\n at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\n--- End of stack trace from previous location where exception was thrown ---\n at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\n at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)\n--- End of stack trace from previous location where exception was thrown ---\n at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()\n at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)\n at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)\n at ****.Services.UserService.Token(RequestUserLoginModel usermodel) in /*******/Services/UserService.cs:line 256\n at ****.Controllers.UsersController.Token(RequestUserLoginModel userParam, String q) in /*******/Controllers/UsersController.cs:line 82",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": null,
"HResult": -2146232060,
"Source": "Core Microsoft SqlClient Data Provider",
"WatsonBuckets": null,
"Errors": null,
"ClientConnectionId": "5206c80f-d8f8-4b12-81e7-b9c51539b6af"
}
}
And when I try to change var dataEmpNo into other name it will change error message
“Message”: “Invalid column name ‘__dataEmpNo_0’.”
follow my variable name too. Same variable name is i use to query. But when i remove config ENV LC_ALL and LANG entity framework it work fine.
Further technical details
Database provider: Microsoft.EntityFrameworkCore.SqlServer 3.1.7 Target framework: netcoreapp3.1 LangVersion 7.1 Microsoft.NET.Sdk.Web Operating system: docker mcr.microsoft.com/dotnet/core/sdk:3.1-buster IDE: . Visual Studio 2019 16.6.0 Microsoft.VisualStudio.ConnectedService.Wcf 15.0.40203.910
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (15 by maintainers)
Note from triage: we will prepare this for a 3.1 patch since it impacts all machines with Thai locale.
This is indeed a bug in EF Core, which has already been fixed for 5.0 - it’s recommended that anyone hitting this try out 5.0.0-rc2, which is go-live ready. #18831 contains a workaround for this for 3.1 (by replacing the RelationalSqlGenerationHelper service).
At the time the decision was made to not patch 3.1 for this, am leaving this issue open to discuss this again in triage.
Hi @uopeydel ,
I did more tests on this one. Based on your repro app, I added two more routes to get the data directly using Microsoft.Data.SqlClient driver. You can find new ValuesController.cs here.
Both
GetDataSyncandGetDataAsynccan retrieve the data from the server successfully when using Thai locale (same docker file you are using). You can see the returned data printed in the Visual Studio output window like this:From our EventSource tracing log, I find that the command texts passing to SqlCommand are different when using Thai locale versus other working locale:
// when using Thai locale
// when using other working locale
You can see that @ sign is missing which causes the SqlException you get.
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name '__data_0'.I think some locale issue happens when passing the parameters to the driver.
Hi @ajcvickers , can someone from efcore side take a look at this issue to see why we are missing
@when using Thai locale?Thanks,
Duplicate of #18831
This look very similar to https://github.com/npgsql/efcore.pg/issues/1508#issuecomment-706487001
@roji @ajcvickers
Does it make sense to transfer the issue to EF Core repo based on @karinazhou 's response above?
@uopeydel That is strange if the application cannot work well with some locales. I will do more testing to dig this deeper.
https://github.com/uopeydel/testdb
use this project step test is run command
docker build --pull --rm -f “dockerfile” -t testdb:latest “.”
docker run -d -p 1144:443/tcp -p 1188:80/tcp testdb:latest
and go to url
http://localhost:1188/api/Values/GetData
It will show you error message
Then comment line below in “dockerfile”
then try to build docker and run again it will be work fine.
** please change ConnectionStrings before test