zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 34 forks source link

how to get Identity Value for each iteration bulk insert #11

Closed mustafaerdogmus closed 7 years ago

mustafaerdogmus commented 7 years ago
        List< IletisimLog> bulkInsertIletisimLog = new List<IletisimLog>();
        //there are 1000 values in the array of paramaters
        foreach (var kId in paramaters)
        {     
            var iletisimLogInsert = new IletisimLog()
            {
                KullaniciID = kId.KullaniciId,
                EklendigiTarih = DateTime.Now,
                GonderildigiTarih = DateTime.Now,
                BilgilendirmeTurID = bilgilendirmeturId,
            };
            bulkInsertIletisimLog.Add(iletisimLogInsert);

        }
        _iLetisimLogService.BulkInsertRange(bulkInsertIletisimLog);

//There are 1000 records registered in the database. How to get the primary key value for each record

JonathanMagnan commented 7 years ago

Hello @musti276 ,

To output record, you will need to specify a mapping. Here is an example using lambda expression

var bulk= new BulkOperation<IletisimLog>(connection);
bulk.DestinationTableName = "IletisimLogs";

// Column Input Expression
bulk.ColumnInputExpression = c => new { c.KullaniciID, c.EklendigiTarih, c.GonderildigiTarih, c.BilgilendirmeTurID };

// Column Output Expression
bulk.ColumnOutputExpression = c => c.IletisimLogID;

bulk.BulkInsert(bulkInsertIletisimLog);

Let me know if that example helped you or if you need more information

Best Regards,

Jonathan

JonathanMagnan commented 7 years ago

Closing comment: No answer, feel free to re-open if you still have questions.