本文整理汇总了C#中DatabaseContext.GetRepository方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseContext.GetRepository方法的具体用法?C# DatabaseContext.GetRepository怎么用?C# DatabaseContext.GetRepository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseContext
的用法示例。
在下文中一共展示了DatabaseContext.GetRepository方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVersionWithArrangement
public void CreateVersionWithArrangement()
{
int arrangementId;
using (DatabaseContext ctx = new DatabaseContext())
{
var arrangementDao = ctx.GetRepository<ArrangementRepository>();
Arrangement arrangement = arrangementDao.Add();
arrangement.BpNumber = "123456789";
arrangement.Name = "Koops";
ctx.SaveChanges();
arrangementId = arrangement.Id;
}
using (DatabaseContext ctx = new DatabaseContext())
{
var arrangementDao = ctx.GetRepository<ArrangementRepository>();
var versionDao = ctx.GetRepository<ArrangementVersionRepository>();
var arrangement = arrangementDao.GetSingle(a => a.Id == arrangementId);
ArrangementVersion version = versionDao.Add();
version.Version = 1;
arrangement.Versions.Add(version);
ctx.SaveChanges();
}
using (DatabaseContext ctx = new DatabaseContext())
{
var arrangementDao = ctx.GetRepository<ArrangementRepository>();
var arrangement = arrangementDao.GetSingle(a => a.Id == arrangementId);
Assert.IsNotEmpty(arrangement.Versions);
Assert.AreEqual(1, arrangement.Versions.Single().Id);
ctx.SaveChanges();
}
}
示例2: CreateUserWithMultipleArrangements
public void CreateUserWithMultipleArrangements()
{
Arrangement arr1, arr2;
using (DatabaseContext ctx = new DatabaseContext())
{
var arrangementDao = ctx.GetRepository<ArrangementRepository>();
{
arr1 = arrangementDao.Add();
arr1.BpNumber = "1";
arr1.Name = "Vendor 1";
arr2 = arrangementDao.Add();
arr2.BpNumber = "2";
arr2.Name = "Vendor 2";
}
var userDao = ctx.GetRepository<UserRepository>();
var user = userDao.Add();
{
user.FullName = "Everest BV";
user.Email = "[email protected]";
user.UserName = "everest_nl";
user.Arrangements.Add(arr1);
user.Arrangements.Add(arr2);
}
ctx.SaveChanges();
{
Assert.AreEqual("Everest BV", user.FullName);
Assert.AreEqual("[email protected]", user.Email);
Assert.AreEqual("everest_nl", user.UserName);
Assert.AreEqual(2, user.Arrangements.Count());
Assert.AreEqual(1, arr1.Users.Count);
Assert.AreEqual(1, arr2.Users.Count);
}
}
}
示例3: 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();
}
}
示例4: 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();
}
}