本文整理汇总了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();
}
示例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();
}
示例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("/");
};
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例8: ReleaseDocumentSession
private static void ReleaseDocumentSession(IKernel kernel, IDocumentSession session)
{
if (session.Advanced.HasChanges)
{
session.SaveChanges();
}
}
示例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;
}
}
示例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));
};
}
示例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("/");
};
}
示例12: SaveChallenge
public static void SaveChallenge(IDocumentSession session, Challenge challenge)
{
challenge.Single = true;
challenge.Category = ChallengeCategory.Miscellaneous;
session.Store(challenge);
session.SaveChanges();
}
示例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();
}
示例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();
}
示例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;
}
}