当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.Update方法代码示例

本文整理汇总了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)));
     }
 }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:9,代码来源:Tests_Modify.cs

示例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));
     }
 }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:9,代码来源:Tests_Modify.cs

示例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));
            }
        }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:11,代码来源:Tests_Modify.cs

示例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)));
            }
        }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:11,代码来源:Tests_Modify.cs

示例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"));
            }
        }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:12,代码来源:Tests_Modify.cs

示例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"));
            }
        }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:11,代码来源:Tests_Modify.cs

示例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"));
     }
 }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:9,代码来源:Tests_Modify.cs

示例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));
            }
        }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:14,代码来源:Tests_Modify.cs

示例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));
     }
 }
开发者ID:ZeroSharp,项目名称:XpoBatch,代码行数:12,代码来源:Tests_Modify.cs

示例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();
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:35,代码来源:ConfigurationDataStore.cs

示例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();
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:34,代码来源:ConfigurationDataStore.cs

示例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;
                //    });
            }
        }
开发者ID:punitganshani,项目名称:KonfDB,代码行数:37,代码来源:ConfigurationDataStore.cs


注:本文中的UnitOfWork.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。