Пример #1
0
        protected void Application_Start()
        {
            DbDatabase.SetInitializer <SitioWebEntities>(new SitioWebInitializer());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
Пример #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            DbDatabase.SetInitializer(new ActivityLogDbInitilaizer());
        }
Пример #3
0
        public static void Start()
        {
            DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

            // Sets the default database initialization code for working with Sql Server Compact databases
            // Uncomment this line and replace CONTEXT_NAME with the name of your DbContext if you are
            // using your DbContext to create and manage your database
            DbDatabase.SetInitializer(new DropCreateCeDatabaseIfModelChanges <TodoContext>());
        }
 public HairAndSolelessContext()
 {
     // Instructions:
     //  * You can add custom code to this file. Changes will *not* be lost when you re-run the scaffolder.
     //  * If you want to regenerate the file totally, delete it and then re-run the scaffolder.
     //  * You can delete these comments if you wish
     //  * If you want Entity Framework to drop and regenerate your database automatically whenever you
     //    change your model schema, uncomment the following line:
     DbDatabase.SetInitializer(new HairAndSolelessInitializer());
 }
        private static void runCodeFirst()
        {
            DbDatabase.SetInitializer <ConferenceModel>(new DropCreateDatabaseAlways <ConferenceModel>());
            using (var context = new ConferenceModel())
            {
                var speaker = new Speaker {
                    FirstName = "Julie", LastName = "Lerman"
                };
                var session = new Session
                {
                    Title           = "Code First Design",
                    ConferenceTrack =
                        new ConferenceTrack {
                        TrackName = "Data", TrackChair = "Damien Guard", MinSessions = 5
                    },
                    Abstract = "tbd",
                };
                var session2 = new Session
                {
                    Title           = "From Sap to Syrup",
                    ConferenceTrack =
                        new ConferenceTrack {
                        TrackName = "Vermont", TrackChair = "Ethan Allen"
                    },
                    Abstract = "How maple syrup is made",
                };
                var speaker2 = new Speaker {
                    FirstName = "Suzanne", LastName = "Shushereba"
                };
                context.Speakers.Add(speaker);
                context.Speakers.Add(speaker2);
                speaker.Sessions = new List <Session>();
                speaker.Sessions.Add(session);
                speaker.Sessions.Add(session2);
                speaker2.Sessions = new List <Session>();
                speaker2.Sessions.Add(session2);
                context.SaveChanges();
            }
            using (var context = new ConferenceModel())
            {
                foreach (var dbSession in context.Sessions.Include("Speakers"))
                {
                    Console.WriteLine();
                    Console.WriteLine(dbSession.Title);
                    Console.WriteLine("Speakers:");

                    foreach (var sessionSpeaker in dbSession.Speakers)
                    {
                        Console.WriteLine(".... {0}", sessionSpeaker.Name);
                    }
                }
                Console.WriteLine("Press Any Key To Continue...");
                Console.ReadKey();
            }
        }
Пример #6
0
        public void InitializeDatabaseTest()
        {
            DbDatabase.SetInitializer(new NotifyIfModelOutOfSync <DatabaseContext>());

            // TODO: Implement unit test

            using (var db = new DatabaseContext())
            {
                db.Database.Initialize(true);
            }
        }
Пример #7
0
    static void Main(string[] args)
    {
        DbDatabase.DefaultConnectionFactory = new System.Data.Entity.Database.SqlConnectionFactory("Data Source=.;Integrated Security=SSPI");
        DbDatabase.SetInitializer <StockContext>(new DropCreateDatabaseIfModelChanges <StockContext>());
        StockContext oContext = new StockContext();

        oContext.StockOrders.Add(new StockOrder {
            StockOrderID = 2, Name = "test"
        });
        oContext.SaveChanges();
    }
Пример #8
0
        public void TableSchemaConventionTest()
        {
            DbDatabase.SetInitializer(new DropCreateDatabaseAlways <DatabaseContext>());

            using (var db = new DatabaseContext())
            {
                db.Database.Initialize(true);

                var expected = typeof(DatabaseContext).GetProperties().Where(x => x.PropertyType.Name == "DbSet`1")
                               .Select(x => new { Namespace = x.PropertyType.GetGenericArguments()[0].FullName, PropertyName = x.Name })
                               .Select(x => { var i1 = x.Namespace.LastIndexOf('.'); var i2 = x.Namespace.LastIndexOf('.', i1 - 1); return(x.Namespace.Substring(i2 + 1, i1 - i2) + x.PropertyName); })
                               .OrderBy(x => x).ToArray();

                var actual = db.Database.SqlQuery <string>(SqlQueries.SelectFullTableNames).ToArray();

                CollectionAssert.AreEqual(expected, actual);
            }
        }
Пример #9
0
 static void Main(string[] args)
 {
     DbDatabase.SetInitializer(new CreateDatabaseIfNotExists <BookDbContext>());
     using (var context = new ShapeDbContext())
     {
         // creating a new object
         context.Polygons.Add(new Polygon {
             Name = "P1", Perimiter = 3
         });
         context.Polygons.Add(new Polygon {
             Name = "P2", Perimiter = 2
         });
         context.SaveChanges();
     }
     using (var context = new ShapeDbContext())
     {
         // creating a new object
         var polygons = context.Polygons.Where(o => o.Perimiter < 3);
         Console.WriteLine(polygons.Count());
     }
 }