Fastest Way of Inserting in Entity Framework

前端 未结 30 2247
鱼传尺愫
鱼传尺愫 2020-11-21 05:23

I\'m looking for the fastest way of inserting into Entity Framework.

I\'m asking this because of the scenario where you have an active TransactionScope a

30条回答
  •  猫巷女王i
    2020-11-21 05:59

    But, for more than (+4000) inserts i recommend to use stored procedure. attached the time elapsed. I did inserted it 11.788 rows in 20"

    thats it code

     public void InsertDataBase(MyEntity entity)
        {
            repository.Database.ExecuteSqlCommand("sp_mystored " +
                    "@param1, @param2"
                     new SqlParameter("@param1", entity.property1),
                     new SqlParameter("@param2", entity.property2));
        }
    

提交回复
热议问题