private static async Task SaveObjectsAsync(Phone p) { using (MobileContext db = new MobileContext()) { db.Phones.Add(p); await db.SaveChangesAsync(); } }
private static async Task DbCommandAsync(Phone p) { using (MobileContext db = new MobileContext()) { System.Data.SqlClient.SqlParameter name = new System.Data.SqlClient.SqlParameter("name", p.Name); System.Data.SqlClient.SqlParameter price = new System.Data.SqlClient.SqlParameter("price", p.Price); await db.Database.ExecuteSqlCommandAsync("INSERT INTO Phones (Name, Price) VALUES (@name, @price)", name, price); } }
public static async Task GetObjectsAsync() { using (MobileContext db = new MobileContext()) { await db.Phones.ForEachAsync(p => { Console.WriteLine("{0} ({1})", p.Name, p.Price); }); } }