none
How to save data in two tables at once request in C# ASP.NET WEB API 2 RRS feed

  • Question

  • How to poset data in two tables at one request in AP.NET WEB API 2,

    I'M USING VS 2015, SQL SEVER 2014, C#.NET.

     // POST: api/Registers
            [ResponseType(typeof(Register))]
            public IHttpActionResult PostRegister(Register register, Registers2 register2)
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }
    
                db.Registers.Add(register);
    
                db2.Registers2.Add(register2);
                db2.SaveChanges();
                db.SaveChanges();
                return CreatedAtRoute("DefaultApi", new { id = register.id }, register);
            }
    

    Saturday, June 24, 2017 7:21 AM

Answers