EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Microsoft.Data.SqlClient.SqlException: 'Conversion failed when converting the nvarchar value 'Value1' to data type int.'

Open t11omas opened this issue 5 years ago • 2 comments

Description

When using an enum which has the enum as string conversion turned on and making use of that in a future query then it fails with a conversion error.

//This works ok builder.Property(e => e.ExampleEnumValue).HasConversion(new EnumToStringConverter<ExampleEnum>()); dbContext.Examples.Where(x => x.ExampleEnumValue == ExampleEnum.Value1);

//This doesn't work

 builder.Property(e => e.ExampleEnumValue).HasConversion(new EnumToStringConverter<ExampleEnum>());
 QueryRequest request = new QueryRequest();
request.ExampleEnum = ExampleEnum.Value1;
dbContext.Examples.Where(x => x.ExampleEnumValue == request.ExampleEnum);

Exception

If you are seeing an exception, include the full exceptions details (message and stack trace). Microsoft.Data.SqlClient.SqlException HResult=0x80131904 Message=Conversion failed when converting the nvarchar value 'Value1' to data type int. Source=Core Microsoft SqlClient Data Provider StackTrace: at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows) at Microsoft.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more) at Microsoft.Data.SqlClient.SqlDataReader.Read() at Z.EntityFramework.Plus.CreateEntityDataReader.Read() at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read() at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.MoveNext() at Z.EntityFramework.Plus.QueryFutureValue1.SetResult(DbDataReader reader) at Z.EntityFramework.Plus.QueryFutureBatch.ExecuteQueries() at Z.EntityFramework.Plus.QueryFutureEnumerable1.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at EFPlusConversion.Program.Main(String[] args) in C:\Users\t11om\source\repos\EFPlusConversion\EFPlusConversion\Program.cs:line 55

This exception was originally thrown at this call stack: [External Code] EFPlusConversion.Program.Main(string[]) in Program.cs

Exception message:
Stack trace:

Fiddle or Project

EFPlusConversion.zip

Note: If you are not able to provide code we can run and that reproduce the issue, we will not be able to fix it either.

Further technical details

  • EF version:
  • EF Plus version:
  • Database Provider:

t11omas avatar Dec 24 '20 08:12 t11omas

Hello @t11omas ,

Thank you for the project, my developer will look at it.

Best Regards,

Jon


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Dec 24 '20 15:12 JonathanMagnan

Hello @t11omas ,

The v5.1.11 has been released.

Could you try it and let me know if my developer successfully fixed your issue correctly?

JonathanMagnan avatar Jan 06 '21 13:01 JonathanMagnan