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

Bug: InsertAll on MSSQL (returns wrong Identifier) #1129

Open
Garios opened this issue Jan 18, 2023 · 1 comment
Open

Bug: InsertAll on MSSQL (returns wrong Identifier) #1129

Garios opened this issue Jan 18, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Garios
Copy link

Garios commented Jan 18, 2023

Bug Description

We have a table:

  • ClientID
  • ID to internal Enumeration
  • Value

Without setting the identifier, it generates the following SQL-Command:

INSERT INTO [Table] ( [ClientID], [ID], [Value]) VALUES ( @ClientID, @ID, @Value ) ;

SELECT CONVERT(BIGINT, @ClientID) AS [Result], @__RepoDb_OrderColumn_0 AS [OrderColumn] ;

The SQL-Command doesn't change, if we set the identifier to ID by:

FluentMapper.Entity<ManagedLogbooks_Types>().Identity(p => p.ID);

Therefore it always returns the value from ClientID:

InsertAll.cs on line 849

do
{
    if (await reader.ReadAsync(cancellationToken))
    {
        // No need to use async on this level (await reader.GetFieldValueAsync<object>(0, cancellationToken))
        var value = Converter.DbNullToNull(reader.GetValue(0));  //!!!!!!!!!!!!!!!!! here
        var index = batchItems.Count > 1 && reader.FieldCount > 1 ? reader.GetInt32(1) : position;
        context.KeyPropertySetterFunc.Invoke(batchItems[index], value);
        result++;
    }
    position++;
}
while (await reader.NextResultAsync(cancellationToken));

Next problem

Assume it returns the correct Field-Value (ID). ID in our special case is an enumeration. In this case it throws an invalid cast exceptionr on the following line:

context.KeyPropertySetterFunc.Invoke(batchItems[index], value);

Message:
Invalid cast from 'System.Int64' to '[EnumerationType]'. 

StackTrace:
   bei System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   bei RepoDb.Converter.ToType[T](Object value)
   bei RepoDb.DbConnectionExtension.<InsertAllAsyncInternalBase>d__364`1.MoveNext()

Library Version:

Example: current master

@Garios Garios added the bug Something isn't working label Jan 18, 2023
@mikependon
Copy link
Owner

Thanks for reporting this issue, we will include the fix to this issue in the next release.

@mikependon mikependon pinned this issue Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants