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

Owned entities with Unique Index throws exception #469

Closed
virzak opened this issue Feb 14, 2022 · 12 comments
Closed

Owned entities with Unique Index throws exception #469

virzak opened this issue Feb 14, 2022 · 12 comments
Assignees

Comments

@virzak
Copy link

virzak commented Feb 14, 2022

Description

Owned entity with a unique index works (with a workaround) in EF Core. See dotnet/efcore#11336

However it throws with EntityFramework-Extensions

Exception

If you are seeing an exception, include the full exceptions details (message and stack trace).

System.Exception
  HResult=0x80131500
  Message=One of your column have a destination mapped more than once. See the inner exception for details.
  Source=Z.EntityFramework.Extensions.EFCore
  StackTrace:
   at Z.BulkOperations.BulkOperation.()
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.BulkOperations.BulkOperation.BulkInsert()
   at .BulkInsert[T](DbContext this, IEntityType entityType, IEnumerable`1 list, Action`1 options, SavingSelector savingSelector, Boolean forceSpecificTypeMapping)
   at .BulkInsert[T](DbContext this, IEnumerable`1 entities, Action`1 options, Boolean isBulkSaveChanges)
   at DbContextExtensions.BulkInsert[T](DbContext this, IEnumerable`1 entities, Action`1 options)
   at DbContextExtensions.BulkInsert[T](DbContext this, IEnumerable`1 entities)
   at Program.<Main>$(String[] args) in Q:\Code\Sandbox\OwnedEntityWithUniqueIndex\OwnedEntityWithUniqueIndex\Program.cs:line 26

  This exception was originally thrown at this call stack:
    Z.BulkOperations.BulkOperation.()

Inner Exception 1:
Exception: The following destination column is mapped more than once: 'ParentId'.

Project

This commit throws an exception

Further technical details

  • EF version: 6
  • EF Extensions version: 6.13.9
  • Database Provider: SqlServer
@JonathanMagnan JonathanMagnan self-assigned this Feb 14, 2022
@JonathanMagnan
Copy link
Member

Hello @virzak ,

The v6.13.10 has been released.

Could you try it and let us know if everything is working with the latest release?

Best Regards,

Jon

@virzak
Copy link
Author

virzak commented Feb 19, 2022

@JonathanMagnan thanks, it passes, but UpdateFromQuery it also an issue.

Here is a breaking commit:

virzak/EntityFramework-Extensions-469@0580263

@virzak
Copy link
Author

virzak commented Feb 21, 2022

DeleteFromQuery seems to work just fine.

@JonathanMagnan
Copy link
Member

Great to hear!

Don't hesitate to contact us if you need anything.

Best regards,

Jon

@virzak
Copy link
Author

virzak commented Feb 21, 2022

@JonathanMagnan, sorry, UpdateFromQuery is still not working.

@virzak
Copy link
Author

virzak commented Feb 21, 2022

Here is the exception:

Microsoft.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=The column 'ParentId' was specified multiple times for 'B'.
  Source=Core Microsoft SqlClient Data Provider
  StackTrace:
   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 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.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
   at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Z.EntityFramework.Extensions.BatchUpdate.<>c.(DbCommand , Nullable`1 )
   at Z.EntityFramework.Extensions.BatchUpdate.Execute[T](IQueryable`1 query, Expression`1 updateFactory)
   at BatchUpdateExtensions.UpdateFromQuery[T](IQueryable`1 query, Expression`1 updateFactory)
   at Program.<Main>$(String[] args) in Q:\Code\Sandbox\OwnedEntityWithUniqueIndex\OwnedEntityWithUniqueIndex\Program.cs:line 33

  This exception was originally thrown at this call stack:
    Microsoft.Data.SqlClient.SqlConnection.OnError(Microsoft.Data.SqlClient.SqlException, bool, System.Action<System.Action>)
    Microsoft.Data.SqlClient.SqlInternalConnection.OnError(Microsoft.Data.SqlClient.SqlException, bool, System.Action<System.Action>)
    Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(Microsoft.Data.SqlClient.TdsParserStateObject, bool, bool)
    Microsoft.Data.SqlClient.TdsParser.TryRun(Microsoft.Data.SqlClient.RunBehavior, Microsoft.Data.SqlClient.SqlCommand, Microsoft.Data.SqlClient.SqlDataReader, Microsoft.Data.SqlClient.BulkCopySimpleResultSet, Microsoft.Data.SqlClient.TdsParserStateObject, out bool)
    Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(Microsoft.Data.SqlClient.SqlDataReader, Microsoft.Data.SqlClient.RunBehavior, string, bool, bool, bool)
    Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(System.Data.CommandBehavior, Microsoft.Data.SqlClient.RunBehavior, bool, bool, int, out System.Threading.Tasks.Task, bool, bool, Microsoft.Data.SqlClient.SqlDataReader, bool)
    Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior, Microsoft.Data.SqlClient.RunBehavior, bool, System.Threading.Tasks.TaskCompletionSource<object>, int, out System.Threading.Tasks.Task, out bool, bool, bool, string)
    Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(System.Threading.Tasks.TaskCompletionSource<object>, bool, int, out bool, bool, bool, string)
    Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    Z.EntityFramework.Extensions.BatchUpdate.(System.Data.Common.DbCommand, int?)
    ...
    [Call Stack Truncated]

@virzak
Copy link
Author

virzak commented Feb 24, 2022

@JonathanMagnan, would be great if you could look into it. I also believe that InsertFromQuery crashes in this scenario.

@JonathanMagnan
Copy link
Member

Thank for reporting,

My developer pushed a fix early this week, I should be able to review it Friday and check if the InsertFromQuery would be fixed at the same time.

@JonathanMagnan
Copy link
Member

Hello @virzak ,

Unfortunately, it will take us some more time.

The code my developer provided fixed this case but some side impacts could happen in some other complex cases.

If no fix is provided next week, we will create a temporary option for you so you will be able to use this features by turning this option to true meanwhile my developer proposed me his fix.

@virzak
Copy link
Author

virzak commented Mar 2, 2022

@JonathanMagnan Thanks so much for the update.

@JonathanMagnan
Copy link
Member

Hello @virzak ,

As promised, since we're not able to complete the full fix, we added an option that will work with this scenario:

EntityFrameworkManager.TmpUseDistinctTableLogic = true;

This option is temporary and will be removed as soon as my developer provides a complete fix (I will give you an update when it happens).

@virzak
Copy link
Author

virzak commented Mar 10, 2022

Thank you, @JonathanMagnan

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