public async Task <IActionResult> Create([Bind("FirstName, LastName")] Author author) { using (var context = new EntityFrameworkDbContext()) { context.Add(author); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } }
public async Task <IActionResult> Create([Bind("Title, AuthorId")] Book book) { using (var context = new EntityFrameworkDbContext()) { context.Books.Add(book); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } }
public async Task Test() { var serializer = new Serializer(new AllPropertiesExtractor()); var customer = new Customer { Age = 1, Name = "qwer", Orders = new[] { new Order { Price = 3, ShippingAddress = "4" }, new Order { Price = 1, ShippingAddress = "2" }, } }; await using var context = new EntityFrameworkDbContext(); await context.Set <TestTable>().AddAsync(new TestTable { Id = 1, CompositeKey = "2", Boolean = false, Integer = 1345, String = "qwerty", DateTime = DateTime.Today, DateTimeOffset = DateTimeOffset.UtcNow, Customer = customer, CustomerSerialized = serializer.Serialize(customer), }); await context.Set <UsersTable>().AddAsync(new UsersTable { Id = 1, Email = "2", Name = "3", }); await context.SaveChangesAsync(); }
public async Task <int> SaveChangesAsync(bool acceptAllChangesOnSuccess = true, CancellationToken cancellationToken = new CancellationToken()) { return(await _context.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken)); }