本文整理汇总了C#中ISession.SaveOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.SaveOrUpdate方法的具体用法?C# ISession.SaveOrUpdate怎么用?C# ISession.SaveOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.SaveOrUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldSaveApproval
public ShouldSaveApproval(ISession session, ISpecimenBuilder fixture)
{
var person = fixture.Create<Person>();
session.SaveOrUpdate(person);
var approval = new Approval { Person = person };
session.SaveOrUpdate(approval);
_approvalId = approval.Id;
}
示例2: ShouldSavePersonWithCategories
public ShouldSavePersonWithCategories(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder)
{
var categories = specimenBuilder.CreateMany<CategoryField>(_count).ToList();
var fake = specimenBuilder.Create<Person>();
var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, categories);
session.SaveOrUpdate(person);
_personId = person.Id;
}
示例3: ShouldSavePersonWithLinks
public ShouldSavePersonWithLinks(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder)
{
var links = specimenBuilder.CreateMany<LinkField>(_count).ToList();
var fake = specimenBuilder.Create<Person>();
var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.Georgetown, null, links);
session.SaveOrUpdate(person);
_personId = person.Id;
}
示例4: Save
private static void Save(ISession session, GridWidget widget)
{
if (widget.Id != Guid.Empty && !session.Contains(widget))
widget = session.Merge(widget);
session.SaveOrUpdate(widget);
session.Flush();
}
示例5: Save
public void Save(ISession session, MovieDB_Movie obj)
{
// populate the database
using (var transaction = session.BeginTransaction())
{
session.SaveOrUpdate(obj);
transaction.Commit();
}
}
示例6: CreateCategories
private IEnumerable<Category> CreateCategories(ISession session, params string[] categoryNames)
{
return categoryNames.Select(x =>
{
var cat = new Category(x);
WithTransaction(session, () => session.SaveOrUpdate(cat));
return cat;
});
}
示例7: AddSomeProducts
private void AddSomeProducts(ISession session, Category category, int count)
{
for (int i = 0; i < count; i++)
{
var product = new Product("Product " + i);
category.AddProduct(product);
}
WithTransaction(session, () => session.SaveOrUpdate(category));
}
示例8: ShouldSavePersonWithLinksRemoved
public ShouldSavePersonWithLinksRemoved(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder, IContainer container)
{
_container = container;
var links = specimenBuilder.CreateMany<LinkField>(_startCount).ToList();
var fake = specimenBuilder.Create<Person>();
var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, null, links);
session.SaveOrUpdate(person);
_personId = person.Id;
}
示例9: Person_should_have_and_remove_some_Categories
public void Person_should_have_and_remove_some_Categories(ISession session)
{
var person = session.Get<Person>(_personId);
person.Categories.Count.ShouldBe(_startCount);
person.RemoveCategory(person.Categories.First());
person.RemoveCategory(person.Categories.Last());
session.SaveOrUpdate(person);
}
示例10: UpdateColumnDescription
public static void UpdateColumnDescription(int columnId, string newDescription, ISession session)
{
var column = session.Query<ColumnEntity>().First(x => x.Id == columnId);
column.Description = newDescription;
using (var transaction = session.BeginTransaction())
{
session.SaveOrUpdate(column);
transaction.Commit();
}
}
示例11: UpdateTableDescription
public static void UpdateTableDescription(int tableId, string newDescription, ISession session)
{
var table = session.Query<TableEntity>().First(x => x.Id == tableId);
table.Description = newDescription;
using(var transaction = session.BeginTransaction())
{
session.SaveOrUpdate(table);
transaction.Commit();
}
}
示例12: CreateFileCreateEventHandler
private static void CreateFileCreateEventHandler(ISession session)
{
var workflow = new DefinedWorkflow();
workflow.Name = "DeleteFileOnCreate";
session.SaveOrUpdate(workflow);
var definedTask = new DefinedTask();
definedTask.Name = "Test";
definedTask.RunCode =
@"foreach(var parameter in parameters)
{
System.Console.WriteLine(""{0}:{1}:{2}"", parameter.Category, parameter.Name, parameter.Value);
}
string hostname = parameters.Where(p => p.Category == ""EventParameter"" && p.Name == ""Client"").Single().Value;
string path = parameters.Where(p => p.Category == ""EventParameter"" && p.Name == ""Path"").Single().Value;
string file = parameters.Where(p => p.Category == ""EventParameter"" && p.Name == ""Filename"").Single().Value;
string filePath = System.IO.Path.Combine(path, file);
System.Console.WriteLine(hostname);
System.Console.WriteLine(filePath);
File.Delete(hostname, filePath);
return 0;";
session.SaveOrUpdate(definedTask);
var definedWorkflowStep = new DefinedWorkflowStep();
definedWorkflowStep.DefinedTask = definedTask;
definedWorkflowStep.DefinedWorkflow = workflow;
session.SaveOrUpdate(definedWorkflowStep);
var nextWorkflowStep = new DefinedNextWorkflowStep();
nextWorkflowStep.DefinedWorkflow = workflow;
nextWorkflowStep.NextStep = definedWorkflowStep;
nextWorkflowStep.PreviousStep = null;
session.SaveOrUpdate(nextWorkflowStep);
var lastWorkflowStep = new DefinedNextWorkflowStep();
lastWorkflowStep.DefinedWorkflow = workflow;
lastWorkflowStep.PreviousStep = definedWorkflowStep;
lastWorkflowStep.NextStep = null;
session.SaveOrUpdate(lastWorkflowStep);
var defaultEventHandler = new EventHandler();
defaultEventHandler.DefinedWorkflow = workflow;
defaultEventHandler.EventGroupTypes = "Filesystem";
defaultEventHandler.EventType = "Add";
session.SaveOrUpdate(defaultEventHandler);
}
示例13: PerformAction
public object PerformAction(Resource resource, ISession dataSession)
{
if (resource.Id == 0)
{
try
{
resource.Tags = resource.Tags.WrapCommas();
dataSession.SaveOrUpdate(resource);
return GenerateResource(resource);
}
catch (Exception exception)
{
return new { status = "failed", exception = exception.ToString() };
}
}
return UpdateExistingResource(resource, dataSession);
}
示例14: ResetPassword
public static void ResetPassword(ISession session, int id, string hash, string newPassword)
{
Login login = session.Load<Login>(id);
if (login == null)
{
throw new Exception(string.Format("Invalid login id '{0}'.", id));
}
if (GetPasswordHash(login.Password) != hash)
{
throw new Exception(string.Format("Invalid hash code '{0}'.", hash));
}
login.Password = GetPasswordHash(newPassword);
session.SaveOrUpdate(login);
session.Flush();
}
示例15: UpdateExistingResource
private static object UpdateExistingResource(Resource resource, ISession dataSession)
{
using (var tx = dataSession.BeginTransaction())
{
var existing = dataSession.CreateCriteria<Resource>()
.Add(Restrictions.IdEq(resource.Id)).UniqueResult<Resource>();
if (existing == null)
{
return new { status = "failed", message = "Resource does not exist" };
}
existing.LongDescription = resource.LongDescription;
existing.ResourceType = resource.ResourceType;
existing.ShortDescription = resource.ShortDescription;
existing.Title = resource.Title;
existing.Uri = resource.Uri;
existing.Tags = resource.Tags.WrapCommas();
dataSession.SaveOrUpdate(existing);
tx.Commit();
}
return GenerateResource(resource);
}