private static void InsertingNewDataWithSubObjects(string fbConnectionString) { using (var db = new FirebirdContext(fbConnectionString)) { var newItemid = db.Items.Max(c => c.Id) + 1; var newDetailId = db.Details.Max(c => c.Ident) + 1; db.Items.Add(new DbItem { Id = newItemid, Name = "Hello from code", LongText = "lorem ipsum dolor sit ammet", Details = new List<DbDetail> { new DbDetail { Name = "Sub obj", NumberValue = DateTime.Now.Second, Date = DateTime.UtcNow, FloatValue = DateTime.Now.Millisecond, Ident = newDetailId, ItemId = newItemid }, new DbDetail { Name = "Sub obj", NumberValue = DateTime.Now.Second, Date = DateTime.UtcNow, FloatValue = DateTime.Now.Millisecond, Ident = newDetailId + 1, ItemId = newItemid } } }); db.SaveChanges(); } }
private static void InsertingNewData(string fbConnectionString) { using (var db = new FirebirdContext(fbConnectionString)) { db.Items.Add(new DbItem { Id = db.Items.Max(c=>c.Id) + 1, Name = "Hello from code", LongText = "lorem ipsum dolor sit ammet" }); db.SaveChanges(); } }
private static void DisplayLastAdded(string fbConnectionString) { using (var db = new FirebirdContext(fbConnectionString)) { var item = db.Items.ToList().Last(); Console.WriteLine("last added item"); Console.WriteLine(item.Id); Console.WriteLine(item.Name); Console.WriteLine(item.LongText); Console.WriteLine("\t\t details"); foreach (var detail in item.Details) { Console.WriteLine(detail.Name); Console.WriteLine(detail.NumberValue); Console.WriteLine(detail.Date); Console.WriteLine(detail.FloatValue); Console.WriteLine(detail.Ident); Console.WriteLine(detail.ItemId); } } }
private static void LazyLoadingSubObjects(string fbConnectionString) { using (var db = new FirebirdContext(fbConnectionString)) { var item = db.Items.First(); var details = item.Details.ToList(); foreach (var detail in details) { Console.WriteLine(detail.Name); Console.WriteLine(detail.NumberValue); Console.WriteLine(detail.Date); Console.WriteLine(detail.FloatValue); Console.WriteLine(detail.Ident); } } }
private static void SimpleGetAll(string fbConnectionString) { using (var db = new FirebirdContext(fbConnectionString)) { var views = db.Views.Select(v => new { v.Name, v.Id }); ListAll(views); } }