UseRowsAffected / ResultInfo - Incorrect syntax near the keyword 'FROM'
Description
I'm having the following problem:
I've built a console application and i'm using this EF Extension operation pack. As I'm doing the bulk merge operation it works like a charm but I've tried to use the option UseRowsAffected and ResultInfo and it throws an error:
Incorrect syntax near the keyword 'FROM'
This is my implementation of the code:

This is my console output:

Exception Message:
Incorrect syntax near the keyword 'FROM'.
Stack trace:
en System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) en System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) en System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) en System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() en System.Data.SqlClient.SqlDataReader.get_MetaData() en System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) en System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
en System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
en System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
en .(DbCommand , BulkOperation , Int32 )
en .( , DbCommand )
en .Execute(List1 actions) en Z.BulkOperations.BulkOperation.Execute() en Z.EntityFramework.Extensions.EntityBulkOperation1.BulkMerge()
en .BulkMerge[T](BulkOperation1 this, DbContext context, List1 list, Boolean isManager, Type type, String typeName)
en .1.(SchemaEntityType ) en System.Collections.Generic.List1.ForEach(Action1 action) en .BulkMerge[T](DbContext this, BulkOperation1 bulkOperation, IEnumerable1 entities2) en DbContextExtensions.BulkMerge[T](DbContext this, IEnumerable1 entities, Action`1 bulkOperationFactory)
en _798_ColectorAPI.ProcesarArchivo.Program.InsertarNormalizados() en D:\Proyectos\Desarrollo\PRD-Clientes\Collector\798_Collector\798_ColectorAPI.ProcesarArchivo\Program.cs:línea 328
Further technical details
- EF version: EF Core 6 / EF 4.5.2
- EF Extensions version: 5.1.22
- Database Provider: SQL Server 13
Hello @facumallia ,
Thank you for reporting, we will look at it.
Best Regards,
Jon
Hello @facumallia ,
Sorry for the long delay, I forget to answer you last week.
My developer tried your scenario but everything seems to have worked:
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab.EFCore30
{
class Request_AuditAlloDuplicateKey
{
public static void Execute()
{
// Create BD
using (var context = new EntityContext())
{
My.DeleteBD(context);
context.Database.EnsureCreated();
}
// CLEAN
using (var context = new EntityContext())
{
context.EntitySimples.RemoveRange(context.EntitySimples);
context.SaveChanges();
}
// SEED
using (var context = new EntityContext())
{
for (int i = 0; i < 3; i++)
{
context.EntitySimples.Add(new EntitySimple { ColumnInt = i });
}
context.SaveChanges();
}
// TEST
using (var context = new EntityContext())
{
var list = context.EntitySimples.ToList();
list.AddRange(context.EntitySimples.ToList());
list.Add(new EntitySimple { ColumnInt = 10 });
list.Add(new EntitySimple { ColumnInt = 11 });
list.Add(new EntitySimple { ColumnInt = 12 });
//var audits = new List<Z.BulkOperations.AuditEntry>();
var resultInfo = new Z.BulkOperations.ResultInfo();
context.BulkMerge(list, option =>
{
option.UseRowsAffected = true;
option.ResultInfo = resultInfo;
option.InsertIfNotExists = true;
//option.UseAudit = true;
//option.AuditEntries = audits;
option.AllowDuplicateKeys = true;
});
}
}
public class EntityContext : DbContext
{
public EntityContext()
{
}
public DbSet<EntitySimple> EntitySimples { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(new SqlConnection(My.ConnectionString));
base.OnConfiguring(optionsBuilder);
}
}
public class EntitySimple
{
public int ID { get; set; }
public int ColumnInt { get; set; }
public string ColumnString { get; set; }
}
}
}
Is it possible for you to provide either a runnable project or the SQL that has been executed (using SQL Profiler or another tool) which throws this error? You can send information in private here [email protected] if needed.
Best Regards,
Jon
Hello @facumallia ,
Since our last conversation, we haven't heard from you.
Don't hesitate to provide a runnable project or the SQL that has been executed.
Looking forward to hearing from you,
Jon
Hello @facumallia ,
A simple reminder that we are here to assist you!
Feel free to provide a runnable project to our support team [email protected]
Best regards,
Jon