Bulk insert using Entity Framework for repository C# Web API -


i have following code inserting data:

empservice.cs

private readonly unitwork _unitofwork;  // unity framework  public messagedetailsentity insertemployee(employeeentity employeeobj) {     using (var scope = new transactionscope())     {         var employee = new employee                            {                                name = employeeobj.name,                                address = employeeobj.address,                                is_active = true                            };         // call genericrepository.cs insert method          _unitofwork.emplopyeerepository.insert(employee);          _unitofwork.save();         scope.complete();     } } 

genericrepository.cs

public class genericrepository<tentity> tentity : class {     internal myentities context;     internal dbset<tentity> dbset;      public genericrepository(myentities context)     {         this.context = context;         this.dbset = context.set<tentity>();     }      public virtual void insert(tentity entity)     {         dbset.add(entity);     } } 

i can use loop inside transactionscope multiple insert , best way it?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -