Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
t11omas opened this issue Dec 24, 2020 · 2 comments
Assignees

Comments

@t11omas
Copy link

t11omas commented Dec 24, 2020

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());
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:
@JonathanMagnan JonathanMagnan self-assigned this Dec 24, 2020
@JonathanMagnan
Copy link
Member

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants