I have a method that adds almost 2000 records at a time, I was using the Bulk Insert and it was working perfectly, however this extension and payment.
So I decided to use the SQLBulkCopy class but I'm having a hard time using it.
I have this class:
public class PessoaNotificacao
{
public int PessoaNotificacaoId { get; set; }
public int PessoaUnidadeId { get; set; }
public int NotificacaoId { get; set; }
public bool Visualizado { get; set; }
public virtual Notificacao Notificacao { get; set; }
public virtual PessoaUnidade PessoaUnidade { get; set; }
}
I have a method with a foreach creates an insert list with approximately 2000 records, the tables that make links are these:
public class Notificacao
{
public int Posicao { get; set; }
public int NotificacaoId { get; set; }
public int CategoriaId { get; set; }
}
e:
public class Pessoa
{
public int PessoaId { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public string Cpf { get; set; }
public string Senha { get; set; }
public string Rg { get; set; }
}
I currently do the insertion this way:
foreach (PessoaUnidade pessoa in pessoas){
var pessoaNotificacao = new PessoaNotificacao
{
Visualizado = false,
PessoaUnidade = pessoa,
Notificacao = notificacao
};
_contexto.PessoaNotificacao.Add(pessoaNotificacao);
}
_contexto.SaveChanges();
But I do not know how to use SqlBulkCopy
, I'm currently studying THIS EXAMPLE but I have not yet achieved anything. If you can not explain how this insertion would work, I would be grateful.
Many thanks to all of you.