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


C# IDocumentSession.SaveChanges方法代码示例

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


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

示例1: delete_documents

        // SAMPLE: deletes
        public void delete_documents(IDocumentSession session)
        {
            var user = new User();

            session.Delete(user);
            session.SaveChanges();

            // OR

            session.Delete(user.Id);
            session.SaveChanges();
        } 
开发者ID:danielmarbach,项目名称:marten,代码行数:13,代码来源:Deletes.cs

示例2: UpdateExistingMessage

        void UpdateExistingMessage(IDocumentSession session, string id, TransportMessage message)
        {
            var failedMessage = session.Load<Message>(id);
            
            var timeOfFailure = DateTimeExtensions.ToUtcDateTime(message.Headers["NServiceBus.TimeOfFailure"]);

            if (failedMessage.FailureDetails.TimeOfFailure == timeOfFailure)
            {
                return;
            }

            if (failedMessage.Status == MessageStatus.Successful && timeOfFailure > failedMessage.ProcessedAt)
            {
                throw new InvalidOperationException("A message can't first be processed successfully and then fail, Id: " + failedMessage.Id);
            }

            if (failedMessage.Status == MessageStatus.Successful)
            {
                failedMessage.FailureDetails = new FailureDetails(message);
            }
            else
            {
                failedMessage.Status = MessageStatus.RepeatedFailure;

                failedMessage.FailureDetails.RegisterException(message);
            }

            session.SaveChanges();
        }
开发者ID:raelyard,项目名称:ServiceBus.Management,代码行数:29,代码来源:ErrorImportSatellite.cs

示例3: WelcomeModule

        public WelcomeModule(IDocumentSession session)
            : base("Welcome")
        {
            Get["/"] = p => View["Welcome"];

            Post["/"] = p =>
            {
                var user = this.Bind<User>("Password", "Salt", "Claims");
                user.Claims = new List<string> {"admin"};
                NSembleUserAuthentication.SetUserPassword(user, Request.Form.Password);
                session.Store(user, "users/" + user.Email);

                session.Store(new Dictionary<string, AreaConfigs>
                                      {
                                          //{"/blog", new AreaConfigs { AreaName = "MyBlog", ModuleName = "Blog" }},
                                          //{"/content", new AreaConfigs { AreaName = "MyContent", ModuleName = "ContentPages" }},
                                          {"/auth", new AreaConfigs { AreaName = "Auth", ModuleName = "Membership" }}
                                      }, Constants.AreasDocumentName);

                session.SaveChanges();

                // Refresh the Areas configs
                AreasResolver.Instance.LoadFromStore(session);

                return Response.AsRedirect("/");
            };
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:27,代码来源:WelcomeModule.cs

示例4: ExecuteAsync

 public override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
 {
     RavenSession = MvcApplication.Store.OpenSession();
     var response = HttpContext.Current.Response;
     var request = HttpContext.Current.Request;
     var origin = request.Headers["Origin"];
     response.Headers.Add(AccessControlAllowOrigin, string.IsNullOrWhiteSpace(origin) ? "*" : origin);
     response.Headers.Add(AccessControlAllowMethods, "OPTIONS, POST, GET, DELETE, HEAD, PUT");
     response.Headers.Add("Access-Control-Allow-Credentials", "true");
     //response.Headers.Add(AccessControlAllowMethods, "GET");
     string requestedHeaders = request.Headers.GetValues(AccessControlRequestHeaders) == null
                                             ? null
                                             : string.Join(", ", request.Headers.GetValues(AccessControlRequestHeaders));
     if (!string.IsNullOrEmpty(requestedHeaders))
     {
         response.Headers.Add(AccessControlAllowHeaders, requestedHeaders);
     }
     return base.ExecuteAsync(controllerContext, cancellationToken).ContinueWith(task =>
         {
             using (RavenSession)
             {
                 if (task.Status != TaskStatus.Faulted && RavenSession != null)
                     RavenSession.SaveChanges();
                 return task;
             }
         }).Unwrap();
 }
开发者ID:robcar,项目名称:getingarna,代码行数:27,代码来源:RavenDbApiController.cs

示例5: SetupUsers

        private static void SetupUsers(IDocumentSession session)
        {
            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "andrea",
                Roles = { "Users", "Administrators" },
            });

            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "administrator",
                Roles = { "Users", "Administrators" },
            });

            //Paolo is a Users with permission for Library/Fake
            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "paolo",
                Roles = { "Users" },
                Permissions =
                    new List<client::Raven.Bundles.Authorization.Model.OperationPermission>
                    {
                        new client::Raven.Bundles.Authorization.Model.OperationPermission
                        {Allow = true, Operation = "Library/Fake"}
                    }
            });

            session.SaveChanges();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:29,代码来源:Mojo2.cs

示例6: ValidateUser

        public static string ValidateUser(IDocumentSession ravenSession, string username, string password)
        {
            // try to get a user from the database that matches the given username and password
            var userRecord = ravenSession.Load<User>("users/" + username);
            if (userRecord == null)
            {
                return null;
            }

            // verify password
            var hashedPassword = GenerateSaltedHash(password, userRecord.Salt);
            if (!CompareByteArrays(hashedPassword, userRecord.Password))
                return null;

            // cleanup expired or unusesd tokens
            foreach (var token in ravenSession.Query<ApiKeyToken>().Where(x => x.UserId == userRecord.Id))
            {
                if (DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(7)) > token.LastActivity)
                    ravenSession.Delete(token);
            }

            // now that the user is validated, create an api key that can be used for subsequent requests
            var apiKey = Guid.NewGuid().ToString();
            ravenSession.Store(new ApiKeyToken { UserId = userRecord.Id, SessionStarted = DateTimeOffset.UtcNow, LastActivity = DateTimeOffset.UtcNow }, GetApiKeyDocumentId(apiKey));
            ravenSession.SaveChanges();

            return apiKey;
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:28,代码来源:NSembleUserAuthentication.cs

示例7: InitialiseTest

        public void InitialiseTest()
        {
            documentStore = new EmbeddableDocumentStore
            {
                RunInMemory = true
            };
            documentStore.Initialize();

            session = documentStore.OpenSession();
            var user1 = new User
            {
                FullName = "FullName1",
                Username = "Username1",
                Password = "Password1",
            };
            session.Store(user1);

            var user2 = new User
            {
                FullName = "FullName2",
                Username = "Username2",
                Password = "Password2",
            };
            session.Store(user2);
            session.SaveChanges();
        }
开发者ID:emanuelgidar,项目名称:RecipesMVC4,代码行数:26,代码来源:AccountControllerTests.cs

示例8: ReleaseDocumentSession

 private static void ReleaseDocumentSession(IKernel kernel, IDocumentSession session)
 {
     if (session.Advanced.HasChanges)
     {
         session.SaveChanges();
     }
 }
开发者ID:pablogq,项目名称:Blog,代码行数:7,代码来源:RavenDbWindsorInstaller.cs

示例9: AddUser

        public void AddUser(User user, IDocumentSession session)
        {
            if (user == null) throw new ArgumentNullException("user");
            if (session == null) throw new ArgumentNullException("session");

            try
            {
                session.Advanced.UseOptimisticConcurrency = true;

                session.Store(user);

                var facebookId = new FacebookId
                                     {
                                         Id = FacebookId.MakeKey(user.FacebookId),
                                         UserId = user.Id
                                     };

                session.Store(facebookId);
                session.SaveChanges();
            }
            finally
            {
                session.Advanced.UseOptimisticConcurrency = false;
            }
        }
开发者ID:rdingwall,项目名称:100books,代码行数:25,代码来源:UserRepository.cs

示例10: BlogAdminModule

        public BlogAdminModule(IDocumentSession session)
            : base("Blog")
        {
            Get["/"] = o =>
                           {
                               return "Blog admin";
                           };

            Get["/post-new/"] = p => View["Edit", new BlogPost
                        {
                            ContentType = DynamicContentType.Markdown,
                            AllowComments = true,
                            CurrentState = BlogPost.State.Draft,
                        }];

            Post["/post-new/"] = p =>
            {
                var post = this.Bind<BlogPost>();

                bool validated = true;
                if (!validated)
                {
                    //ModelState.AddModelError("Id", "");
                    return View["Edit", post];
                }

                session.Store(post);
                session.SaveChanges();

                return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", post.Id, "/", post.Slug));
            };
        }
开发者ID:jchannon,项目名称:NSemble,代码行数:32,代码来源:BlogAdminModule.cs

示例11: TemplatesModule

        public TemplatesModule(IDocumentSession session, IViewLocator viewLocator)
            : base("Templates")
        {
            Get["/"] = p =>
                           {
                               var templates = session.Advanced.LoadStartingWith<ViewTemplate>("NSemble/Views/");
                               return View["List", templates];
                           };

            Get["/new/"] = p => View["Edit", new ViewTemplate {}];

            Get[@"/edit/{viewName*}"] = p =>
                                            {
                                                var viewName = (string) p.viewName;
                                                if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
                                                    viewName = Constants.RavenViewDocumentPrefix + viewName;
                                                var template = session.Load<ViewTemplate>(viewName);

                                                // Even if we don't have it stored in the DB, it might still exist as a resource. Try loading it from Nancy.
                                                if (template == null)
                                                {
                                                    var vlr = viewLocator.LocateView(viewName.Substring(Constants.RavenViewDocumentPrefix.Length), Context);
                                                    if (vlr == null)
                                                        return 404;

                                                    template = new ViewTemplate
                                                                   {
                                                                       Location = vlr.Location,
                                                                       Name = vlr.Name,
                                                                       Extension = vlr.Extension,
                                                                       Contents = vlr.Contents.Invoke().ReadToEnd(),
                                                                   };
                                                }

                                                return View["Edit", template];
                                            };

            Post[@"/edit/{viewName*}"] = p =>
                                                   {
                                                       var template = this.Bind<ViewTemplate>();

                                                       var viewName = (string) p.viewName;
                                                       if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
                                                           viewName = Constants.RavenViewDocumentPrefix + viewName;

                                                       session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));
                                                       session.SaveChanges();

                                                       return "Success";
                                                   };

            Post["/new"] = p =>
                                {
                                    var template = this.Bind<ViewTemplate>();
                                    session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));

                                    return Response.AsRedirect("/");
                                };
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:59,代码来源:TemplatesModule.cs

示例12: SaveChallenge

        public static void SaveChallenge(IDocumentSession session, Challenge challenge)
        {
           challenge.Single = true;
           challenge.Category = ChallengeCategory.Miscellaneous;
           session.Store(challenge);
           session.SaveChanges();

        }
开发者ID:meridiumlabs,项目名称:Meridium.Onboarding,代码行数:8,代码来源:RavenService.cs

示例13: Execute

 public void Execute(IDocumentSession ravenSession, Func<DateTime> now)
 {
     LastExecution = now();
     var nextExecution = Command.ExecuteAndGetNext(ravenSession, now, NextExecution);
     IsActive = nextExecution < DateTime.MaxValue;
     NextExecution = nextExecution;
     ravenSession.SaveChanges();
 }
开发者ID:sofipacifico,项目名称:CommonJobs,代码行数:8,代码来源:ScheduleTask.cs

示例14: RavenSessionTest

        public RavenSessionTest()
        {
            Store = new EmbeddableDocumentStore
                         {
                             RunInMemory = true,
                             DataDirectory = "RavenData",
                         };

            Store.Initialize();
            IndexCreation.CreateIndexes(typeof(RavenIndexes).Assembly, Store);
            Session = Store.OpenSession();

            var user = DataGenerator.GenerateDomainModelUser();

            Session.Store(user);
            Session.SaveChanges();

            var list = DataGenerator.GenereateDomainModelList();

            Session.Store(list);
            Session.SaveChanges();

            var p1 = new Domain.Models.Place
            {
                Description =
                    "Nice selection of guest ales, Live dodgy eighties rock bands. Perfect.",
                Latitude = 52.002324f,
                Longitude = -0.5734f,
                Name = "The Duck and Drake",
                List = "lists/1"
            };
            var p2 = new Domain.Models.Place
            {
                Description =
                    "Kinda trendy place - multiple rooms, decent beer from Leeds brewary and guests",
                Latitude = 52.002324f,
                Longitude = -0.5734f,
                Name = "The Adelphi",
                List = "lists/1"
            };

            Session.Store(p1);
            Session.Store(p2);
            Session.SaveChanges();
        }
开发者ID:PaulCampbell,项目名称:ATP,代码行数:45,代码来源:RavenSessionTest.cs

示例15: ExecuteAsync

		public override async Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
		{
			using (DocumentSession = DocumentStore.OpenSession())
			{
				HttpResponseMessage result = await base.ExecuteAsync(controllerContext, cancellationToken);
				DocumentSession.SaveChanges();
				return result;
			}
		}
开发者ID:ayende,项目名称:nuget.perf,代码行数:9,代码来源:RavenController.cs


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