Skip to content

Commit

Permalink
Merge pull request #296 from bjaminp/master
Browse files Browse the repository at this point in the history
Support long for identity type in sqlite
  • Loading branch information
borisdj committed Mar 24, 2020
2 parents 760e2bd + 6ff5d5b commit 81aaa92
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions EFCore.BulkExtensions/SqlBulkOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,26 @@ public static async Task InsertAsync<T>(DbContext context, IList<T> entities, Ta
{
command.CommandText = SqlQueryBuilderSqlite.SelectLastInsertRowId();
long lastRowIdScalar = (long)command.ExecuteScalar();
int lastRowId = (int)lastRowIdScalar;
var identityPropertyInteger = false;
var accessor = TypeAccessor.Create(typeof(T), true);
string identityPropertyName = tableInfo.PropertyColumnNamesDict.SingleOrDefault(a => a.Value == tableInfo.IdentityColumnName).Key;
if (accessor.GetMembers().FirstOrDefault(x => x.Name == identityPropertyName)?.Type == typeof(int))
{
identityPropertyInteger = true;
}
for (int i = entities.Count -1; i >= 0; i--)
{
accessor[entities[i], identityPropertyName] = lastRowId;
lastRowId--;
if (identityPropertyInteger)
{
accessor[entities[i], identityPropertyName] = (int) lastRowIdScalar;

}
else
{
accessor[entities[i], identityPropertyName] = lastRowIdScalar;
}

lastRowIdScalar--;
}
}
}
Expand Down

0 comments on commit 81aaa92

Please sign in to comment.