Beispiel #1
0
        static int AddTask(AsanaContext db)
        {
            var task = db.Tasks.Where(t => t.Name == "Make the tea").FirstOrDefault();
            if (task == null)
            {
                task = db.Tasks.Create();
                task.Name = "Make the tea";
                task.CreatedAt = DateTime.Now;
                task.Followers.Add(db.Followers.Add(new Follower { User = db.Users.Where(u => u.Name == "Frank Zappa").FirstOrDefault() }));
                task.Followers.Add(db.Followers.Add(new Follower { User = db.Users.Where(u => u.Name == "Tom Waits").FirstOrDefault() }));
                db.Tasks.Add(task);
            }

            return db.SaveChanges();
        }
Beispiel #2
0
        static int AddUsers(AsanaContext db)
        {
            if (db.Users.Where(u => u.Name == "Frank Zappa").FirstOrDefault() == null)
            {
                db.Users.Add(new AsanaUser { Name = "Frank Zappa", Email = "*****@*****.**" });
            }

            if (db.Users.Where(u => u.Name == "Bob Dylan").FirstOrDefault() == null)
            {
                db.Users.Add(new AsanaUser { Name = "Bob Dylan", Email = "*****@*****.**" });
            }

            if (db.Users.Where(u => u.Name == "Tom Waits").FirstOrDefault() == null)
            {
                db.Users.Add(new AsanaUser { Name = "Tom Waits", Email = "*****@*****.**" });
            }

            return db.SaveChanges();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // Database.SetInitializer<AsanaContext>(new DropCreateDatabaseAlways<AsanaContext>());
            //Database.SetInitializer<AsanaContext>(new DropCreateDatabaseIfModelChanges<AsanaContext>());

            using (var db = new AsanaContext())
            {

               // create users
                Console.WriteLine(AddUsers(db));
                Console.WriteLine(AddTask(db));

                var task = db.Tasks.Where(t => t.Name == "Make the tea").FirstOrDefault();

                foreach (var f in task.Followers)
                {
                    Console.WriteLine(f.User.Name);
                }
                Console.ReadLine();

            }
        }