本文整理汇总了C#中UnitOfWork.Update方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Update方法的具体用法?C# UnitOfWork.Update怎么用?C# UnitOfWork.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.Update方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_ModifyAll_Enum
public void Test_ModifyAll_Enum()
{
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
Assert.Less(uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.EnumProperty == new OperandValue(MyEnum.Blue)), 1000);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { EnumProperty = MyEnum.Blue }, null);
Assert.AreEqual(1000, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.EnumProperty == new OperandValue(MyEnum.Blue)));
}
}
示例2: Test_ModifyAll_Integer
public void Test_ModifyAll_Integer()
{
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
Assert.Less(uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.IntegerProperty == 23), 1000);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { IntegerProperty = 23 }, null);
Assert.AreEqual(1000, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.IntegerProperty == 23));
}
}
示例3: Test_ModifyNone_Integer
public void Test_ModifyNone_Integer()
{
CriteriaOperator criteria = CriteriaOperator.Parse("1=0");
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
int affectedRecords = uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.IntegerProperty == 23);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { IntegerProperty = 23 }, criteria);
Assert.AreEqual(affectedRecords, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.IntegerProperty == 23));
}
}
示例4: Test_ModifyNone_Enum
public void Test_ModifyNone_Enum()
{
CriteriaOperator criteria = CriteriaOperator.Parse("1=0");
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
int affectedRecords = uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.EnumProperty == new OperandValue(MyEnum.Blue));
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { EnumProperty = MyEnum.Blue }, criteria);
Assert.AreEqual(affectedRecords, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.EnumProperty == new OperandValue(MyEnum.Blue)));
}
}
示例5: Test_ModifySome_String
public void Test_ModifySome_String()
{
CriteriaOperator criteria = MySimpleObject.Fields.EnumProperty == new OperandValue(MyEnum.Blue);
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
int affectedRecords = uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz" & !criteria)
+ uow.GetObjectCount<MySimpleObject>(criteria);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { StringProperty = "abcdefghjiklmnopqrstuvwxyz" }, criteria);
Assert.AreEqual(affectedRecords, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz"));
}
}
示例6: Test_ModifyNone_String
public void Test_ModifyNone_String()
{
CriteriaOperator criteria = CriteriaOperator.Parse("1=0");
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
int affectedRecords = uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz");
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { StringProperty = "abcdefghjiklmnopqrstuvwxyz" }, criteria);
Assert.AreEqual(affectedRecords, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz"));
}
}
示例7: Test_ModifyAll_String
public void Test_ModifyAll_String()
{
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
Assert.Less(uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz"), 1000);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { StringProperty = "abcdefghjiklmnopqrstuvwxyz" }, null);
Assert.AreEqual(1000, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.StringProperty == "abcdefghjiklmnopqrstuvwxyz"));
}
}
示例8: Test_ModifySome_ReferenceObject
public void Test_ModifySome_ReferenceObject()
{
CriteriaOperator criteria = CriteriaOperator.Parse("1=0");
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
var referenceObject = uow.FindObject<MyReferenceObject>(null);
Assert.AreNotEqual(Guid.Empty, referenceObject);
Guid referenceId = referenceObject.Id;
int affectedRecords = uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.ReferenceProperty.Id == referenceId);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { ReferenceProperty = referenceObject }, criteria);
Assert.AreEqual(affectedRecords, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.ReferenceProperty.Id == referenceId));
}
}
示例9: Test_ModifyAll_ReferenceObject
public void Test_ModifyAll_ReferenceObject()
{
using (UnitOfWork uow = new UnitOfWork(DefaultDataLayer))
{
var referenceObject = uow.FindObject<MyReferenceObject>(null);
Assert.AreNotEqual(Guid.Empty, referenceObject);
Guid referenceId = referenceObject.Id;
Assert.Less(uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.ReferenceProperty.Id == referenceId), 1000);
uow.Update<MySimpleObject>(() => new MySimpleObject(uow) { ReferenceProperty = referenceObject }, null);
Assert.AreEqual(1000, uow.GetObjectCount<MySimpleObject>(MySimpleObject.Fields.ReferenceProperty.Id == referenceId));
}
}
示例10: UpdateServer
public ServerModel UpdateServer(ServerModel model)
{
if (model == null)
throw new ArgumentNullException("model");
Server ServerInDb;
using (var unitOfWork = new UnitOfWork(_connectionString))
{
bool userAuthorised = UserAuthorizedToAccessSuite(unitOfWork, model.UserId, model.SuiteId,
new[] {RoleType.Admin});
if (!userAuthorised)
throw new UnauthorizedUserException(
"User does not have access or sufficient privileges for this action to suite: " + model.SuiteId);
ServerInDb =
unitOfWork.Context.Servers.FirstOrDefault(
x => x.ServerId == model.ServerId && x.SuiteId == model.SuiteId);
if (ServerInDb != null)
{
ServerInDb.Description = model.Description;
ServerInDb.ServerName = model.ServerName;
unitOfWork.Update(ServerInDb);
}
else
{
throw new InvalidOperationException("No Server exists with id:" + model.ServerId + " and suite id: " +
model.SuiteId);
}
}
return ServerInDb.ToModel();
}
示例11: UpdateEnvironment
public EnvironmentModel UpdateEnvironment(EnvironmentModel model)
{
if (model == null)
throw new ArgumentNullException("model");
Environment environmentInDb;
using (var unitOfWork = new UnitOfWork(_connectionString))
{
bool userAuthorized = UserAuthorizedToAccessSuite(unitOfWork, model.UserId, model.SuiteId,
new[] {RoleType.Admin});
if (!userAuthorized)
throw new UnauthorizedUserException(
"User does not have access or sufficient privileges for this action to suite:" + model.SuiteId);
environmentInDb =
unitOfWork.Context.Environments.FirstOrDefault(
x => x.EnvironmentId == model.EnvironmentId && x.SuiteId == model.SuiteId);
if (environmentInDb != null)
{
environmentInDb.EnvironmentTypeId = (int) model.EnvironmentType;
environmentInDb.EnvironmentName = model.EnvironmentName;
unitOfWork.Update(environmentInDb);
}
else
{
throw new InvalidOperationException("No environment exists with id:" + model.EnvironmentId +
" and suite id: " + model.SuiteId);
}
}
return environmentInDb.ToModel();
}
示例12: UpdateSuite
public void UpdateSuite(SuiteModel suiteModel)
{
if (suiteModel == null) return;
using (var unitOfWork = new UnitOfWork(_connectionString))
{
bool userAuthorized = UserAuthorizedToAccessSuite(unitOfWork, suiteModel.UserId, suiteModel.SuiteId,
new[] {RoleType.Admin});
if (!userAuthorized)
throw new UnauthorizedUserException("User does not have enough privileges to perform this action");
Suite suiteInDB = unitOfWork.Context.Suites.FirstOrDefault(x => x.SuiteId == suiteModel.SuiteId);
if (suiteInDB == null)
throw new UnauthorizedUserException("User does not have enough privileges to perform this action");
suiteInDB.IsActive = suiteModel.IsActive;
suiteInDB.PrivateKey = suiteModel.PrivateKey;
suiteInDB.SuiteName = suiteModel.SuiteName;
suiteInDB.UsesSysEncryption = suiteModel.UsesSysEncryption;
unitOfWork.Update(suiteInDB);
//unitOfWork.Update<Application, ApplicationModel>(suiteInDB.Applications,
// suiteModel.Applications,
// application => application.ApplicationId,
// userModel => userModel.ApplicationId.GetValueOrDefault(-1),
// userModel =>
// {
// var dbObject = userModel.ToNewDbObject();
// dbObject.SuiteId = suiteInDB.SuiteId;
// dbObject.IsActive = true;
// return dbObject;
// });
}
}