Esempio n. 1
0
        static void Main(string[] args)
        {
            using (var db = new AuctionSiteDbContext())
            {
                //db.Users.Add(new User()
                //{
                //    Name = "marekch"
                //});
                var users = db.Users.AsNoTracking().AsEnumerable();
                foreach (var user in users)
                {
                    Console.WriteLine(user.UserName);
                }

                //db.SaveChanges();
            }


            Console.WriteLine("press enter to end...");
            Console.ReadLine();
        }
Esempio n. 2
0
        private static DbContext InitializeDatabase()
        {
            var dbCxt = new AuctionSiteDbContext(Effort.DbConnectionFactory.CreatePersistent(TestDbConnection));

            foreach (var dbCxtUser in dbCxt.Users)
            {
                dbCxt.Users.Remove(dbCxtUser);
            }


            dbCxt.Items.RemoveRange(dbCxt.Items);
            dbCxt.Categories.RemoveRange(dbCxt.Categories);
            dbCxt.ItemCategories.RemoveRange(dbCxt.ItemCategories);
            dbCxt.EmailTemplates.RemoveRange(dbCxt.EmailTemplates);

            dbCxt.SaveChanges();

            #region Categories
            var alcohol = new Category
            {
                CategoryType = "Alcohol",
                Description  = "Vse, co obsahuje znamky alkoholu"
            };


            var randomHouseStuff = new Category
            {
                CategoryType = "RandomHouseStuff",
                Description  = "veci z baraku"
            };

            dbCxt.Categories.AddOrUpdate(alcohol);
            dbCxt.Categories.AddOrUpdate(randomHouseStuff);

            #endregion

            #region Users

            dbCxt.Users.AddOrUpdate(User1);
            dbCxt.Users.AddOrUpdate(User2);

            #endregion

            dbCxt.SaveChanges();

            #region Items


            ItemUser1.Owner   = User1;
            ItemUser1.OwnerID = User1.Id;
            ItemUser2.Owner   = User2;
            ItemUser2.OwnerID = User2.Id;

            dbCxt.Items.AddOrUpdate(ItemUser1);
            dbCxt.Items.AddOrUpdate(ItemUser2);
            #endregion

            dbCxt.SaveChanges();

            #region Categories

            ItemUser1.HasCategories = new List <ItemCategory>
            {
                new ItemCategory
                {
                    Category   = alcohol,
                    CategoryID = alcohol.Id,
                    Item       = ItemUser1,
                    ItemID     = ItemUser1.Id
                }
            };

            ItemUser2.HasCategories = new List <ItemCategory>
            {
                new ItemCategory
                {
                    Category   = alcohol,
                    CategoryID = alcohol.Id,
                    Item       = ItemUser2,
                    ItemID     = ItemUser2.Id
                }, new ItemCategory
                {
                    Category   = randomHouseStuff,
                    CategoryID = randomHouseStuff.Id,
                    Item       = ItemUser2,
                    ItemID     = ItemUser2.Id
                }
            };

            #endregion

            dbCxt.SaveChanges();
            return(dbCxt);
        }