本文整理汇总了C#中Repository.SaveOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.SaveOrUpdate方法的具体用法?C# Repository.SaveOrUpdate怎么用?C# Repository.SaveOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.SaveOrUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: uploadMiasta_Click
protected void uploadMiasta_Click(object sender, EventArgs e)
{
if(fileMiasta.HasFile)
{
MemoryStream stream = new MemoryStream(fileMiasta.FileBytes);
XmlReaderSettings settings = new XmlReaderSettings();
int i = 0;
Repository<City, Guid> cityrep = new Repository<City, Guid>();
using (XmlReader r = XmlReader.Create(stream, settings))
{
XPathDocument xpathDoc = new XPathDocument(r);
XPathNavigator xpathNav = xpathDoc.CreateNavigator();
string xpathQuery = "/teryt/catalog/row/col[attribute::name='NAZWA']";
XPathExpression xpathExpr = xpathNav.Compile(xpathQuery);
XPathNodeIterator xpathIter = xpathNav.Select(xpathExpr);
while (xpathIter.MoveNext())
{
City city = new City();
city.Name = xpathIter.Current.Value;
cityrep.SaveOrUpdate(city);
if (i % 500 == 0)
HBManager.Instance.GetSession().Flush();
i++;
//AddressManager.InsertCity(new City { Name = xpathIter.Current.Value });
}
}
HBManager.Instance.GetSession().Flush();
}
}
示例2: TestCreateMoreParty
public void TestCreateMoreParty()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
Employee employee = new Employee()
{
Name = "Bob",
};
Post post = new Post()
{
Name = "總經理室副主管",
};
Post parentPost = postRepository.Query(q => q.Name == "總經理室主管").First();
employeeRepository.SaveOrUpdate(employee);
postRepository.SaveOrUpdate(post);
PartyService partyService = new PartyService(partyHierarchyRepository);
partyService.AddAccountability(parentPost, post);
unitwork.SaveChanges();
partyService.AddEmployeeToPost(post, employee);
unitwork.SaveChanges();
}
}
示例3: Main
private const string ConnectionString = "server=localhost;user id=root;persistsecurityinfo=True;database=supervkappdb"; //
#endregion Fields
#region Methods
static void Main(string[] args)
{
var nhibernatehelper = new NHibernateHelper(ConnectionString);
var unitofwork = new UnitOfWork(nhibernatehelper.SessionFactory);
//попробуем чонить добавить в бд
var user = new UserDomain
{
//Id = "egorveidt", какого черта я сделал интовый айдишник, фаак !!! переделать
FirstName = "Егор",
LastName = "Пичугов",
Age = 21,
Male = true
};
var post = new PostDomain
{
Date = new DateTime(2016, 01, 07),
Text = "test text exst",
};
post.AddSnapshot(new PostSnapshotDomain()
{
CountComments = 1,
CountLikes = 10,
CountReposts = 2,
Date = new DateTime(2016, 01, 07)
});
user.AddPost(post);
var userRepository = new Repository<UserDomain>(unitofwork.Session);
userRepository.SaveOrUpdate(user);
unitofwork.Commit();
}
示例4: TestAddChild
public void TestAddChild()
{
IStore store = new ThreadStaticStore();
IDbContextFactory contextFactory = new DbContextFactory();
using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
{
IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
IRepository<DemoChild, Guid> demoChildRepository = new Repository<DemoChild, Guid>(store);
IRepository<DemoBrother, Guid> demoBrotherRepository = new Repository<DemoBrother, Guid>(store);
Demo demo = new Demo()
{
Name = "C"
};
DemoChild child = new DemoChild();
demo.Children.Add(child);
DemoBrother brother = new DemoBrother();
demo.Brothers.Add(brother);
demoRepository.SaveOrUpdate(demo);
demoChildRepository.SaveOrUpdate(child);
demoBrotherRepository.SaveOrUpdate(brother);
unitwork.SaveChanges();
}
}
示例5: TestCreateParty
public void TestCreateParty()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
//用partyRepository也可以存進去,不知差別在哪
IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
Employee employee = new Employee()
{
Name = "Allen"
};
Post post = new Post()
{
Name = "總經理室主管"
};
employeeRepository.SaveOrUpdate(employee);
postRepository.SaveOrUpdate(post);
PartyService partyService = new PartyService(partyHierarchyRepository);
partyService.AddEmployeeToPost(post,employee);
unitwork.SaveChanges();
}
}
示例6: TestData
public void TestData()
{
IStore store = new ThreadStaticStore();
IDbContextFactory contextFactory = new DbContextFactory();
using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
{
IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store);
Demo demo = new Demo() { Name = "B"};
demoRepository.SaveOrUpdate(demo);
unitwork.SaveChanges();
}
}
示例7: TestCreateEntity
public void TestCreateEntity()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
Entity entity = new Entity()
{
Name = "頁面"
};
Entity childEntity = new Entity()
{
Name = "Section"
};
entity.ChildEntity.Add(childEntity);
IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);
repository.SaveOrUpdate(entity);
repository.SaveOrUpdate(childEntity);
unitwork.SaveChanges();
}
}
示例8: TestAddRole
// [TestMethod]
public void TestAddRole()
{
// create the role
_session.BeginTransaction();
var roleRepo = new Repository<Role>(_session);
var roleId = Guid.Parse("7C270960-0C16-4812-9CEF-275EA308A1AD");
var role = new Role("TestRole " + roleId);
role.Id = roleId;
roleRepo.SaveOrUpdate(role);
_session.Transaction.Commit();
}
示例9: TestAddPartyToOrganization
public void TestAddPartyToOrganization()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
Organization org1 = new Organization()
{
Name = "總經理室"
};
organRepository.SaveOrUpdate(org1);
Party party1 = partyRepository.Query(q => q.Name == "總經理室主管").First();
Party party2 = partyRepository.Query(q => q.Name == "總經理室副主管").First();
org1.Parties.Add(party1);
org1.Parties.Add(party2);
unitwork.SaveChanges();
}
}
示例10: TestAddPermission
//.........这里部分代码省略.........
Organization = orgRepository.Query(q => q.Name == "人資部").First(),
Entity = entRepository.Query(q => q.Name == "Admin").First(),
Operation = oerRepository.Query(q => q.Comment == "View").First(),
Level = 0
};
Permission per3 = new Permission()
{
Organization = orgRepository.Query(q => q.Name == "人資部").First(),
Entity = entRepository.Query(q => q.Name == "Employees").First(),
Operation = oerRepository.Query(q => q.Comment == "View").First(),
Level = 0
};
//企畫課員可以全權管理Admin下的技能設定,職稱設定,假期設定
Permission per4 = new Permission()
{
Party = prtRepository.Query(q => q.Name == "企畫課成員").First(),
Entity = entRepository.Query(q => q.Name == "Admin").First(),
Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
Level = 0
};
//企畫課長(副課長)可以全權管理Organization
Permission per5 = new Permission()
{
Party = prtRepository.Query(q => q.Name == "企畫課副主管").First(),
Entity = entRepository.Query(q => q.Name == "Organization").First(),
Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
Level = 0
};
//管理課對Admin下的所有功能只有View
Permission per6 = new Permission()
{
Organization = orgRepository.Query(q => q.Name == "管理課").First(),
Entity = entRepository.Query(q => q.Name == "Admin").First(),
Operation = oerRepository.Query(q => q.Comment == "View").First(),
Level = 0
};
//管理課對Admin下的所有功能只有View,下次要做檢查重複
//Permission per7 = new Permission()
//{
// Organization = orgRepository.Query(q => q.Name == "管理課").First(),
// Entity = entRepository.Query(q => q.Name == "Admin").First(),
// Operation = oerRepository.Query(q => q.Comment == "View").First(),
// Level = 0
//};
//管理課可以全權管理Employees下的基本資料,技能指定,組織設定
Permission per8 = new Permission()
{
Organization = orgRepository.Query(q => q.Name == "管理課").First(),
Entity = entRepository.Query(q => q.Name == "Employees").First(),
Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
Level = 0
};
//管理課長(副課長)可以查詢員工請假報表
Permission per9 = new Permission()
{
Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
Entity = entRepository.Query(q => q.Name == "員工請假報表").First(),
Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
Level = 0
};
//所以理論上管理課長對Report有View的權限
Permission per10 = new Permission()
{
Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
Entity = entRepository.Query(q => q.Name == "Reports").First(),
Operation = oerRepository.Query(q => q.Comment == "View").First(),
Level = 0
};
//企畫課對Employees下的所有功能只有View
Permission per11 = new Permission()
{
Organization = orgRepository.Query(q => q.Name == "企畫課").First(),
Entity = entRepository.Query(q => q.Name == "Employees").First(),
Operation = oerRepository.Query(q => q.Comment == "View").First(),
Level = 0
};
perRepository.SaveOrUpdate(per1);
perRepository.SaveOrUpdate(per2);
perRepository.SaveOrUpdate(per3);
perRepository.SaveOrUpdate(per4);
perRepository.SaveOrUpdate(per5);
perRepository.SaveOrUpdate(per6);
perRepository.SaveOrUpdate(per8);
perRepository.SaveOrUpdate(per9);
perRepository.SaveOrUpdate(per10);
perRepository.SaveOrUpdate(per11);
unitwork.SaveChanges();
}
}
示例11: InsertTestEntity
protected void InsertTestEntity(string name)
{
var testEntityRepository = new Repository<TestEntity>();
var testEntity = new TestEntity
{
Name = name
};
testEntityRepository.SaveOrUpdate(testEntity);
NHibernateSession.Current.Evict(testEntity);
}
示例12: should_persist_Audit_Role
public void should_persist_Audit_Role()
{
var auditRepo = new Repository<AuditLog>(Session);
var roleId = Guid.Parse("7C270960-0C16-4812-9CEF-275EA308A1AD");
// create the role
Session.BeginTransaction();
var roleRepo = new Repository<Role>(Session);
var role = new Role("TestRole " + roleId) {Id = roleId};
roleRepo.SaveOrUpdate(role);
Session.Transaction.Commit();
Session.Evict(role);
// assert exists in the audit log
var exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 1 && a.EventType == "A" && a.EntityName == "Role");
//Assert.True(exists.Any());
// Update
Session = null;
Session = Container.Resolve<ISessionFactory>().OpenSession();
// fine the role and modify the role
Session.BeginTransaction();
roleRepo = new Repository<Role>(Session);
role = roleRepo.Get(roleId);
role.UpdateValue("TestRoleX");
Session.Transaction.Commit();
Session.Evict(role);
auditRepo = new Repository<AuditLog>(Session);
exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 2 && a.EventType == "M" && a.EntityName == "Role");
//Assert.True(exists.Any());
// delete
Session = null;
Session = Container.Resolve<ISessionFactory>().OpenSession();
roleRepo = new Repository<Role>(Session);
role = roleRepo.Get(roleId);
Session.BeginTransaction();
roleRepo.Delete(role);
Session.Transaction.Commit();
auditRepo = new Repository<AuditLog>(Session);
exists = auditRepo.Where(a => a.RecordId == roleId && a.CommitVersion.Value == 3 && a.EventType == "D" && a.EntityName == "Role");
}
示例13: TestAddEmployeeToPost
public void TestAddEmployeeToPost()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
IRepository<Post, Guid> roleRepository = new Repository<Post, Guid>(store);
IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);
Employee prt1 = new Employee() { Name = "Allen" };
Employee prt2 = new Employee() { Name = "Bob" };
Employee prt3 = new Employee() { Name = "Cary" };
Employee prt4 = new Employee() { Name = "David" };
Employee prt5 = new Employee() { Name = "Edward" };
Employee prt6 = new Employee() { Name = "Fred" };
Employee prt7 = new Employee() { Name = "Gallon" };
Employee prt8 = new Employee() { Name = "Hellen" };
Employee prt9 = new Employee() { Name = "Ian" };
Employee prt10 = new Employee() { Name = "Ivy" };
Employee prt11 = new Employee() { Name = "Jay" };
Employee prt12 = new Employee() { Name = "Kalad" };
Employee prt13 = new Employee() { Name = "Larry" };
Employee prt14 = new Employee() { Name = "Moppies" };
Employee prt15 = new Employee() { Name = "Nana" };
Employee prt16 = new Employee() { Name = "Outu" };
empRepository.SaveOrUpdate(prt1);
empRepository.SaveOrUpdate(prt2);
empRepository.SaveOrUpdate(prt4);
empRepository.SaveOrUpdate(prt5);
empRepository.SaveOrUpdate(prt6);
empRepository.SaveOrUpdate(prt7);
empRepository.SaveOrUpdate(prt8);
empRepository.SaveOrUpdate(prt9);
empRepository.SaveOrUpdate(prt10);
empRepository.SaveOrUpdate(prt11);
empRepository.SaveOrUpdate(prt12);
empRepository.SaveOrUpdate(prt13);
empRepository.SaveOrUpdate(prt14);
empRepository.SaveOrUpdate(prt15);
empRepository.SaveOrUpdate(prt16);
PartyService service = new PartyService(partyHireRepository);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室主管").First(), prt1);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室副主管").First(), prt2);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室秘書").First(), prt3);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部主管").First(), prt4);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部副主管").First(), prt5);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課主管").First(), prt6);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課副主管").First(), prt7);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課成員").First(), prt8);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課主管").First(), prt9);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課副主管").First(), prt10);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課成員").First(), prt11);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部主管").First(), prt12);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部副主管").First(), prt13);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課主管").First(), prt14);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課副主管").First(), prt15);
service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課成員").First(), prt16);
unitwork.SaveChanges();
}
}
示例14: TestAddParty
public void TestAddParty()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);
Post post1 = new Post() { Name = "總經理室主管" };
Post post2 = new Post() { Name = "總經理室副主管" };
Post post3 = new Post() { Name = "總經理室秘書" };
Post post4 = new Post() { Name = "人資部主管" };
Post post5 = new Post() { Name = "人資部副主管" };
Post post6 = new Post() { Name = "企畫課主管" };
Post post7 = new Post() { Name = "企畫課副主管" };
Post post8 = new Post() { Name = "企畫課成員" };
Post post9 = new Post() { Name = "管理課主管" };
Post post10 = new Post() { Name = "管理課副主管" };
Post post11 = new Post() { Name = "管理課成員" };
Post post12 = new Post() { Name = "業務部主管" };
Post post13 = new Post() { Name = "業務部副主管" };
Post post14 = new Post() { Name = "業務一課主管" };
Post post15 = new Post() { Name = "業務一課副主管" };
Post post16 = new Post() { Name = "業務一課成員" };
postRepository.SaveOrUpdate(post1);
postRepository.SaveOrUpdate(post2);
postRepository.SaveOrUpdate(post3);
postRepository.SaveOrUpdate(post4);
postRepository.SaveOrUpdate(post5);
postRepository.SaveOrUpdate(post6);
postRepository.SaveOrUpdate(post7);
postRepository.SaveOrUpdate(post8);
postRepository.SaveOrUpdate(post9);
postRepository.SaveOrUpdate(post10);
postRepository.SaveOrUpdate(post11);
postRepository.SaveOrUpdate(post12);
postRepository.SaveOrUpdate(post13);
postRepository.SaveOrUpdate(post14);
postRepository.SaveOrUpdate(post15);
postRepository.SaveOrUpdate(post16);
unitwork.SaveChanges();
PartyService service = new PartyService(partyHireRepository);
service.AddAccountability(post1, post2);
unitwork.SaveChanges();
service.AddAccountability(post1, post3);
unitwork.SaveChanges();
service.AddAccountability(post1, post4);
unitwork.SaveChanges();
service.AddAccountability(post1, post12);
unitwork.SaveChanges();
service.AddAccountability(post4, post5);
unitwork.SaveChanges();
service.AddAccountability(post4, post6);
unitwork.SaveChanges();
service.AddAccountability(post4, post9);
unitwork.SaveChanges();
service.AddAccountability(post6, post7);
unitwork.SaveChanges();
service.AddAccountability(post6, post8);
unitwork.SaveChanges();
service.AddAccountability(post9, post10);
unitwork.SaveChanges();
service.AddAccountability(post9, post11);
unitwork.SaveChanges();
service.AddAccountability(post12, post13);
unitwork.SaveChanges();
service.AddAccountability(post12, post14);
unitwork.SaveChanges();
service.AddAccountability(post14, post15);
unitwork.SaveChanges();
service.AddAccountability(post14, post16);
unitwork.SaveChanges();
}
}
示例15: TestAddOrganization
public void TestAddOrganization()
{
using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
{
IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
IRepository<OrganizationHierarchy, Guid> organHireRepository = new Repository<OrganizationHierarchy, Guid>(store);
Organization org1 = new Organization() { Name = "總經理室" };
Organization org2 = new Organization() { Name = "人資部" };
Organization org3 = new Organization() { Name = "業務部" };
Organization org4 = new Organization() { Name = "企畫課" };
Organization org5 = new Organization() { Name = "管理課" };
Organization org6 = new Organization() { Name = "業務一課" };
Organization org7 = new Organization() { Name = "業務二課" };
Organization org8 = new Organization() { Name = "業務三課" };
organRepository.SaveOrUpdate(org1);
organRepository.SaveOrUpdate(org2);
organRepository.SaveOrUpdate(org3);
organRepository.SaveOrUpdate(org4);
organRepository.SaveOrUpdate(org5);
organRepository.SaveOrUpdate(org6);
organRepository.SaveOrUpdate(org7);
organRepository.SaveOrUpdate(org8);
unitwork.SaveChanges();
OrganizationService service = new OrganizationService(organHireRepository);
service.AddOrganizationHierarchy(org1, org2, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org1, org3, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org2, org4, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org2, org5, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org3, org6, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org3, org7, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
service.AddOrganizationHierarchy(org3, org8, OrganizationHierarchyType.AM);
unitwork.SaveChanges();
}
}