0
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

Komal12
  • 3,340
  • 4
  • 16
  • 25
mustafaerdogmus
  • 111
  • 1
  • 2
  • 9

1 Answers1

1

As you loop through the Entities to add them to the database, if there is a primary key on there, the Id that is assigned to each will be reflected in the object.

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);

foreach (var inserted in bulkInsertIletisimLog)
{
    // Get the ID of the inserted object
    var newId = inserted.Id;
}

Assuming primary key value on your object is called Id.

Luke
  • 22,826
  • 31
  • 110
  • 193