c# - How add multiple rows with one Insert query in EF -
i have list of strings of unknown length. i'm adding them database:
if (somentenovasclas.any()) { foreach (string item in wsclassificacoes) { dc.classificacaos.add(new classificacao { descricao = item }); } dc.savechanges(); }
but ef generate 1 insert
each row:
exec sp_executesql n'insert [dbo].[classificacao]([descricao], [excluido]) values (@0, @1) select [codclassificacao] [dbo].[classificacao] @@rowcount > 0 , [codclassificacao] = scope_identity()',n'@0 varchar(255),@1 bit',@0='mercado',@1=0 go exec sp_executesql n'insert [dbo].[classificacao]([descricao], [excluido]) values (@0, @1) select [codclassificacao] [dbo].[classificacao] @@rowcount > 0 , [codclassificacao] = scope_identity()',n'@0 varchar(255),@1 bit',@0='concorrĂȘncia',@1=0 go
i'd know how insert in 1 time ef generate command like:
insert table (column) values ([array[0]]), ([array[1]]), ...
instead of 1 insert foreach.. ideas?
check out post: fastest way of inserting in entity framework
entity framework isn't meant out of box, looks people have created extensions: https://efbulkinsert.codeplex.com/
Comments
Post a Comment