示例#1
0
 public void CanInitializeDatabase()
 {
     using (var db = new PetMedsContext()) {
         Database.SetInitializer(new DropCreateDatabaseAlways <PetMedsContext>());
         db.Database.Initialize(force: true);
     }
 }
示例#2
0
        public void CanStoreEntitiesWithValueObjectProperties()
        {
            int petId;

            var petSampson = Pet.Create("Sampson");

            petSampson.Photo = new PetPhotoValueObject
                                   (System.IO.File.ReadAllBytes("..\\..\\sampson.gif"),
                                   "Sampson's Bed?");
            using (var db = new PetMedsContext()) {
                db.Pets.Add(petSampson);
                db.SaveChanges();
                petId = petSampson.Id;
            }
            using (var db = new PetMedsContext()) {
                var petfromdb = db.Pets.Find(petId);
                Assert.AreEqual(petSampson.Photo.ToString(), petfromdb.Photo.ToString());
            }
        }
示例#3
0
        public void CanPersistForeignKeysWithoutNavigationProperty()
        {
            var pet = Pet.Create("Sampson");

            pet.Meds.Add(new Medication {
                Name = "Happy Pills"
            });
            Database.SetInitializer(new DropCreateDatabaseAlways <PetMedsContext>());
            using (var db = new PetMedsContext()) {
                db.Database.Initialize(force: true);
                db.Database.Log = Console.WriteLine;
                db.Pets.Add(pet);
                db.SaveChanges();
            }
            using (var db = new PetMedsContext()) {
                var dbPet = db.Pets.Include(p => p.Meds).FirstOrDefault();
                Assert.AreNotEqual(0, dbPet.Meds.Count());
            }
        }