Пример #1
0
        static void Main(string[] args)
        {
            var blog = new Blog {
                Url = "my link"
            };
            var posts = new List <Post>
            {
                new Post {
                    Content = "content 1", Title = "Title1"
                },
                new Post {
                    Content = "content 2", Title = "Title2"
                },
                new Post {
                    Content = "content 3", Title = "Title3"
                },
                new Post {
                    Content = "content 4", Title = "Title4"
                },
                new Post {
                    Content = "content 5", Title = "Title5"
                },
            };

            blog.Posts.AddRange(posts);


            var db = new BloggingContextFactory().CreateDbContext(new string[0]);

            Console.WriteLine("Deleting database...");
            db.Database.EnsureDeleted();

            //doesn't run the migration to build the UDF
            //Console.WriteLine("Creating database");
            //db.Database.EnsureCreated();

            //creates the database and runs all migrations
            Console.WriteLine("Creating database and running migrations");
            db.Database.Migrate();


            db.Blogs.Add(blog);
            db.SaveChanges();
            var foo = "foo";
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to EF Core Learning session");

            //case 1
            DataAccess.DataContext objContext = new BloggingContextFactory().CreateDbContext(null);

            // objContext.Database.Migrate();

            //  objContext.Users.Add(new DataAccess.Entities.User { Firstname = "jkd", Password = "******" });
            // objContext.Roles.Add(new DataAccess.Entities.Role { Name = "SalesHead" });

            objContext.UserRoles.Add(new DataAccess.Entities.UserRole {
                UserID = 1, RoleID = 1
            });
            objContext.SaveChanges();

            var rls = objContext.Roles.AsNoTracking();

            Console.ReadLine();
        }