public ActionResult RunCreate2() { var db = new InheritanceMappingContext(); //var tmpId = db.BillingDetails.Select(o => o.BillingDetailId).DefaultIfEmpty().Max(); Random tmpRandom = new Random(); db.Cameras.Add(new Camera { //Id = 1, Caption = $"Caption-{RandomUtil.GetLetters(3)}", Manufacturer = $"Manufacturer-{RandomUtil.GetLetters(3)}", TypeNumber = $"TypeNumber-{RandomUtil.GetLetters(3)}", Lens = $"Lens-{RandomUtil.GetLetters(3)}" }); db.SingleReflexCameras.Add(new SingleReflexCamera() { //Id = 2, Caption = $"Caption-{RandomUtil.GetLetters(3)}", Manufacturer = $"Manufacturer-{RandomUtil.GetLetters(3)}", TypeNumber = $"TypeNumber-{RandomUtil.GetLetters(3)}", LensMount = $"LensMount-{RandomUtil.GetLetters(3)}" }); db.Lenses.Add(new Lens() { //Id = 3, Caption = $"Caption-{RandomUtil.GetLetters(3)}", Manufacturer = $"Manufacturer-{RandomUtil.GetLetters(3)}", TypeNumber = $"TypeNumber-{RandomUtil.GetLetters(3)}", FocalLength = $"FocalLength-{RandomUtil.GetLetters(3)}", MaxAperture = $"MaxAperture-{RandomUtil.GetLetters(3)}" }); db.SaveChanges(); return(View()); }
public ActionResult RunCreate() { var db = new InheritanceMappingContext(); var tmpId = db.BillingDetails.Select(o => o.BillingDetailId).DefaultIfEmpty().Max(); Random tmpRandom = new Random(); db.BillingDetails.Add(new CreditCard { BillingDetailId = ++tmpId, Owner = $"Owner-{RandomUtil.GetLetters(3)}", Number = tmpRandom.Next(100).ToString(), CardType = tmpRandom.Next(3), ExpiryMonth = tmpRandom.Next(12).ToString(), ExpiryYear = tmpRandom.Next(99).ToString(), }); db.BillingDetails.Add(new BankAccount { BillingDetailId = ++tmpId, Owner = $"Owner-{RandomUtil.GetLetters(3)}", Number = tmpRandom.Next(100).ToString(), BankName = $"BankName-{RandomUtil.GetLetters(3)}", Swift = $"Swift-{RandomUtil.GetLetters(3)}", }); db.SaveChanges(); return(View()); }
public ActionResult RunDeleteCreditCard() { var db = new InheritanceMappingContext(); var data = db.BillingDetails.OfType <CreditCard>().First(); db.BillingDetails.Remove(data); db.SaveChanges(); return(View()); }
public ActionResult RunOnModelCreating() { using (var model = new InheritanceMappingContext()) { model.Database.Delete(); model.Database.Create(); } return(View()); }
private static void Main(string[] args) { //TPH using (var db = new InheritanceMappingContext()) { var ba1 = new BankAccount_TPH { Owner = "qqqq", Number = "1", BankName = "www", Swift = "eeeee" }; var ba2 = new BankAccount_TPH { Owner = "aaaaa", Number = "2", BankName = "ssssss", Swift = "ddddd" }; var cr1 = new CreditCard_TPH { Owner = "zzzz", Number = "3", CardType = 1, ExpiryMonth = "1", ExpiryYear = "2017" }; var cr2 = new CreditCard_TPH { Owner = "xxxxx", Number = "4", CardType = 2, ExpiryMonth = "2", ExpiryYear = "2017" }; db.BillingDetail_TPHs.Add(ba1); db.BillingDetail_TPHs.Add(ba2); db.BillingDetail_TPHs.Add(cr1); db.BillingDetail_TPHs.Add(cr2); db.SaveChanges(); foreach (var bd in db.BillingDetail_TPHs) { Console.WriteLine("{0}", bd.Number); } } //TPT using (var context = new InheritanceMappingContext()) { var creditCard = new CreditCard_TPT { Number = "987654321", CardType = 1 }; var user = new User_TPT { UserId = 1, BillingInfo = creditCard }; context.User_TPTs.Add(user); context.SaveChanges(); } using (var context = new InheritanceMappingContext()) { var user = context.User_TPTs.Find(1); Debug.Assert(user.BillingInfo is CreditCard_TPT); } //TPC using (var context = new InheritanceMappingContext()) { var bankAccount = new BankAccount_TPC { BillingDetailId = 1 }; var creditCard = new CreditCard_TPC { BillingDetailId = 2, CardType = 1 }; context.BillingDetail_TPCs.Add(bankAccount); context.BillingDetail_TPCs.Add(creditCard); context.SaveChanges(); } Console.ReadKey(); }
protected override void Seed(InheritanceMappingContext context) { MyEntity entity = new MyEntity() {