示例#1
0
 public static void CreateDB()
 {
     using (InheritanceMappingContext db = new InheritanceMappingContext()) {
         if (!db.Database.Exists())
         {
             db.Database.Initialize(true);
             db.Database.CreateIfNotExists();
             db.Dispose();
         }
     }
 }
示例#2
0
        public static void GetUserLazyOrDefaultLoading()
        {
            InheritanceMappingContext db = new InheritanceMappingContext();
            var user = db.User.FirstOrDefault();

            db.Dispose();
            foreach (var rec in user.GetType().GetProperties())
            {
                Console.WriteLine($"{rec.Name}: {rec.GetValue(user)}");
            }

            Console.ReadLine();
        }
示例#3
0
        public static void GetUserEgerLoading()
        {
            InheritanceMappingContext db = new InheritanceMappingContext();
            var user = db.User.Include("BillingInfo").FirstOrDefault();

            db.Dispose();
            foreach (var rec in user.GetType().GetProperties())
            {
                Console.WriteLine($"{rec.Name}: {rec.GetValue(user)}");
            }
            Console.WriteLine($"{ user.BillingInfo}: ->");
            foreach (var rec in user.BillingInfo.GetType().GetProperties())
            {
                Console.WriteLine($"{rec.Name}: {rec.GetValue(user.BillingInfo)}");
            }

            Console.ReadLine();
        }
示例#4
0
        public static void AddCreditCardThroughUser()
        {
            CreateDB();
            InheritanceMappingContext db = new InheritanceMappingContext();
            var Crd = new CreditCard()
            {
                CardType    = 1,
                ExpiryMonth = "Feb",
                ExpiryYear  = "2020",
                Number      = "10",
                NumberA     = 10.ToString(),
                Owner       = "me"
            };
            var user = new User()
            {
                BillingInfo = Crd,
                FirstName   = "me",
                LastName    = "me"
            };

            db.User.Add(user);
            db.SaveChanges();
            db.Dispose();
        }