当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseContext.SaveChanges方法代码示例

本文整理汇总了C#中DatabaseContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseContext.SaveChanges方法的具体用法?C# DatabaseContext.SaveChanges怎么用?C# DatabaseContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseContext的用法示例。


在下文中一共展示了DatabaseContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clear

 public static void Clear()
 {
     using (var context = new DatabaseContext())
     {
         context.Schedules.RemoveRange(context.Schedules);
         context.SaveChanges();
         context.Cases.RemoveRange(context.Cases);
         context.SaveChanges();
         context.ResetTokens.RemoveRange(context.ResetTokens);
         context.SaveChanges();
         context.Users.RemoveRange(context.Users);
         context.SaveChanges();
     }
 }
开发者ID:Cognite-Soft,项目名称:ARB_2016_V2,代码行数:14,代码来源:Database.cs

示例2: CreateActiveUser

 public static UserEntity CreateActiveUser(string email, Role role)
 {
     using (var context = new DatabaseContext())
     {
         var passwordManager = new PasswordManager(new Configuration());
         var salt = passwordManager.GenerateSalt();
         var hashedPassword = passwordManager.HashPassword(Password, salt);
         var enctyptedSecurePhrase = passwordManager.EncryptSecurePhrase(Phrase);
         var user = new UserEntity
         {
             Id = Guid.NewGuid(),
             Email = email,
             FirstName = email,
             LastName = email,
             Role = role,
             UserState = UserState.Activated,
             PasswordSalt = salt,
             HashedPassword = hashedPassword,
             EncryptedSecurePhrase = enctyptedSecurePhrase,
             FirstSecurePhraseQuestionCharacterIndex = 0,
             SecondSecurePhraseQuestionCharacterIndex = 1,
         };
         context.Users.Add(user);
         context.SaveChanges();
         return user;
     }
 }
开发者ID:Cognite-Soft,项目名称:ARB_2016_V2,代码行数:27,代码来源:Database.cs

示例3: CreateArrangementWithUsers

        public void CreateArrangementWithUsers()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                ArrangementRepository repository = new ArrangementRepository(ctx);
                var arrangement = repository.Add();

                arrangement.Name = "Koops Furness";
                arrangement.BpNumber = "123456789";

                var user1 = new User() {UserName = "user1", Email = "[email protected]", FullName = "User One"};
                var user2 = new User() {UserName = "user2", Email = "[email protected]", FullName = "User Two"};

                arrangement.Users.Add(user1);
                arrangement.Users.Add(user2);

                Assert.IsTrue(arrangement.Id == 0);
                Assert.IsTrue(user1.Id == 0);
                Assert.IsTrue(user2.Id == 0);

                ctx.SaveChanges();

                Assert.IsTrue(arrangement.Id > 0);
                Assert.IsTrue(user1.Id > 0);
                Assert.IsTrue(user2.Id > 0);
                Assert.AreEqual(arrangement, user1.Arrangements.Single());
                Assert.AreEqual(arrangement, user2.Arrangements.Single());
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:29,代码来源:ArrangementTests.cs

示例4: CreateUser

 public void CreateUser(UserData user)
 {
     using (var context = new DatabaseContext())
     {
         var entity = new UserEntity(user);
         context.Users.Add(entity);
         context.SaveChanges();
     }
 }
开发者ID:Cognite-Soft,项目名称:ARB_2016_V2,代码行数:9,代码来源:Database.cs

示例5: UpdateUser

 public void UpdateUser(UserData user)
 {
     using (var context = new DatabaseContext())
     {
         var entity = context.Users.FirstOrDefault(x => x.Email == user.Email);
         entity.Update(user);
         context.SaveChanges();
     }
 }
开发者ID:Cognite-Soft,项目名称:ARB_2016_V2,代码行数:9,代码来源:Database.cs

示例6: InsertUser

 public void InsertUser(String email)
 {
     using (var ctx = new DatabaseContext())
     {
         if (ExistsUser(email))
             throw new UserBusinessException("Email já cadastrado.");
         ctx.User.Add(user);
         ctx.SaveChanges();
     }
 }
开发者ID:frc1983,项目名称:TrabalhoFinalPSA,代码行数:10,代码来源:UserBusiness.cs

示例7: Seed

        public void Seed(DatabaseContext context)
        {
            context.Database.CreateIfNotExists();

            context.Suppliers.Add(new Supplier { GUID = Guid.NewGuid(), Name = "Super Man", Description = "can do anything" });
            context.Suppliers.Add(new Supplier { GUID = Guid.NewGuid(), Name = "Spider Man", Description = "eats only spiders" });
            context.Suppliers.Add(new Supplier { GUID = Guid.NewGuid(), Name = "Iron Man", Description = "supply iron" });
            context.Suppliers.Add(new Supplier { GUID = Guid.NewGuid(), Name = "Ben 10", Description = "alian troubles" });
            context.Suppliers.Add(new Supplier { GUID = Guid.NewGuid(), Name = "Mr Been", Description = "Very reliable" });
            context.SaveChanges();

            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "Rubber Duck", Price = 345, Supplier = context.Suppliers.FirstOrDefault(s => s.Name=="Super Man")});
            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "Metalic Pen", Price = 356, Supplier = context.Suppliers.FirstOrDefault(s => s.Name == "Iron Man") });
            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "White Cap", Price = 443, Supplier = context.Suppliers.FirstOrDefault(s => s.Name == "Spider Man") });
            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "Bottle Wine", Price = 424 });
            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "Paper Bag", Price = 765 });
            context.Products.Add(new Product { GUID = Guid.NewGuid(), Name = "Sheet Tan", Price = 325 });
            context.SaveChanges();
        }
开发者ID:hasith,项目名称:codekernel,代码行数:19,代码来源:SeedSampleData.cs

示例8: Delete

        public void Delete(int id)
        {
            var db = new DatabaseContext();
            var concept = db.Concepts.FirstOrDefault(f => f.Id == id);

            if (concept == null)
                throw new Exception("the concept that you want to delete is not exists in the db in the first place.");

            db.Concepts.Remove(concept);
            db.SaveChanges();
        }
开发者ID:Mohamed-Ahmed-Abdullah,项目名称:CarWorkshop,代码行数:11,代码来源:ApiConceptController.cs

示例9: OnClickSave

        protected void OnClickSave(object sender, EventArgs e)
        {
            var button = (Button)sender;

            var imageId = int.Parse(button.CommandArgument);

            using (var db = new DatabaseContext())
            {
                var image = db.Images.First(l => l.Id == imageId);
                image.TimeApproved = DateTime.UtcNow;
                db.SaveChanges();
            }
        }
开发者ID:ElrHolis,项目名称:hitchBOT,代码行数:13,代码来源:imageGrid.master.cs

示例10: AddMechanicJobType

        public void AddMechanicJobType(string mechanicJobType)
        {
            if (string.IsNullOrWhiteSpace(mechanicJobType))
                throw new Exception("please privide a mechanicJobType");

            var db = new DatabaseContext();
            var dbCarType = db.MechanicJobTypes.ToList().FirstOrDefault(f => f.ArabicName.Trim() == mechanicJobType.Trim());
            if (dbCarType != null)
                return;

            db.MechanicJobTypes.Add(new MechanicJobType { ArabicName = mechanicJobType });
            db.SaveChanges();
        }
开发者ID:Mohamed-Ahmed-Abdullah,项目名称:CarWorkshop,代码行数:13,代码来源:ApiMechanicJobController.cs

示例11: CreateVersionWithoutArrangement

        public void CreateVersionWithoutArrangement()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var dao = ctx.GetRepository<ArrangementVersionRepository>();

                ArrangementVersion version = dao.Add();
                version.Version = 1;
                // Oeps, no arrangement version is set !!

                ctx.SaveChanges();
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:13,代码来源:ArrangementVersionTests.cs

示例12: Delete

        public void Delete(int id)
        {
            if (id == 0)
                throw new Exception("please privide id");

            var db = new DatabaseContext();
            var sparePartJob = db.SparePartJobs.FirstOrDefault(f => f.Id == id);

            if (sparePartJob == null)
                throw new Exception("you are tring to delete an item that is already deleted");

            db.SparePartJobs.Remove(sparePartJob);
            db.SaveChanges();
        }
开发者ID:Mohamed-Ahmed-Abdullah,项目名称:CarWorkshop,代码行数:14,代码来源:ApiSparePartJobController.cs

示例13: CreateUserWithoutArrangement

        public void CreateUserWithoutArrangement()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var userRepos = ctx.GetRepository<UserRepository>();
                var user = userRepos.Add();
                {
                    user.Email = "[email protected]";
                    user.FullName = "Everest BV";
                    user.UserName = "everest_nl";
                }

                ctx.SaveChanges();
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:15,代码来源:UserTests.cs

示例14: InsertMovie

        public void InsertMovie(Int32 movieId, String login)
        {
            using (var ctx = new DatabaseContext())
            {
                var user = ctx.User.Where(x => x.Email.ToLower().Equals(login)).First();
                if (user == null)
                    throw new MovieBusinessException("Usuário não cadastrado.");

                var userMovie = ctx.UserCollection.FirstOrDefault(x => x.User.Id.Equals(user.Id) && x.MovieId.Equals(movieId));

                if (userMovie != null)
                    throw new MovieBusinessException("Filme já cadastrado na sua coleção.");

                ctx.UserCollection.Add(new UserCollection() { User = user, MovieId = movieId });
                ctx.SaveChanges();
            }
        }
开发者ID:frc1983,项目名称:TrabalhoFinalPSA,代码行数:17,代码来源:MovieBusiness.cs

示例15: Index

        public ActionResult Index()
        {
            var mvcName = typeof(Controller).Assembly.GetName ();
            var isMono = Type.GetType ("Mono.Runtime") != null;

            ViewData ["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor;
            ViewData ["Runtime"] = isMono ? "Mono" : ".NET";

            using (var entities = new DatabaseContext ()) {
                entities.Histories.Add (new History () {
                    IPAddress = this.Request.UserHostAddress,
                    VisitTime = DateTime.Now,
                    Uri = this.Request.Url.AbsoluteUri
                });
                entities.SaveChanges ();
            }

            return View ();
        }
开发者ID:cloveryang,项目名称:MonoAspnetMvcRazor,代码行数:19,代码来源:HomeController.cs


注:本文中的DatabaseContext.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。