public async Task <Product> CraeteAsync(Product entity) { var res = await ctx.Products.AddAsync(entity); await ctx.SaveChangesAsync(); return(res.Entity); }
/// <summary> /// async: The method will be containing the Asynchronous call /// and this method returns Task Object /// await: The statement performs Async operation on separate thread /// other than calling thread and the async method will returns response /// to the calling thread /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <Category> CraeteAsync(Category entity) { // new Category will be added in DbSet var result = await ctx.Categories.AddAsync(entity); // the transaction will be commited by adding new category in // Categories table await ctx.SaveChangesAsync(); // newly created Category will be returned return(result.Entity); }