Пример #1
0
        static void PopulatedDataToDB()
        {
            using (var context = new IssueTrackingContext())
            {
                var giulianop = context.Users.Add(
                    new User
                {
                    Name     = "giulianop",
                    FullName = "Giuliano Pizzocaro"
                });

                var tinusv = context.Users.Add(
                    new User
                {
                    Name     = "tinusv",
                    FullName = "Tinus Van Eck"
                });

                var repo = context.Repos.Add(
                    new Repo
                {
                    Name      = repoDetails,
                    CreatedBy = giulianop,
                    CreatedOn = DateTime.Now
                });

                var issue = context.Issues.Add(
                    new Enhancement
                {
                    Repo      = repo,
                    Title     = "Consider porting to EF Core",
                    CreatedBy = giulianop,
                    CreatedOn = DateTime.Now,
                    Assignees = new List <User> {
                        giulianop, tinusv
                    },
                    Votes = 1
                });

                var comment = context.Comments.Add(
                    new Comment
                {
                    Issue     = issue,
                    Text      = "Are we done yet?",
                    CreatedBy = giulianop,
                    CreatedOn = DateTime.Now
                });

                context.SaveChanges();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Re - create database
            using (var context = new IssueTrackingContext())
            {
                context.Database.Delete();
                context.Database.CreateIfNotExists();
            }

            // Seed data
            using (var context = new IssueTrackingContext())
            {
                var divega = context.Users.Add(
                    new User
                {
                    Name     = "divega",
                    FullName = "Diego Vega"
                });

                var smitpatel = context.Users.Add(
                    new User
                {
                    Name     = "smitpatel",
                    FullName = "Smit Patel"
                });

                var repo = context.Repos.Add(
                    new Repo
                {
                    Name      = "PortEF6ToCore",
                    CreatedBy = divega,
                    CreatedOn = DateTime.Now
                });

                var issue = context.Issues.Add(
                    new Enhancement
                {
                    Repo      = repo,
                    Title     = "Consider porting to EF Core",
                    CreatedBy = divega,
                    CreatedOn = DateTime.Now,
                    Assignees = new List <User> {
                        divega, smitpatel
                    },
                    Votes = 1
                });

                var comment = context.Comments.Add(
                    new Comment
                {
                    Issue     = issue,
                    Text      = "Are we done yet?",
                    CreatedBy = divega,
                    CreatedOn = DateTime.Now
                });

                context.SaveChanges();
            }

            // Execute query and show results
            using (var context = new IssueTrackingContext())
            {
                var query =
                    context.Repos.Where(r => r.Name == "PortEF6ToCore")
                    .Include(r => r.CreatedBy)
                    .Include(r => r.Issues.Select(i => i.Assignees))
                    .Include(r => r.Issues.Select(i => i.Comments));

                var results = query.ToList();

                Show(context.Issues.Local);
            }
        }