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


C# Session.Update方法代码示例

本文整理汇总了C#中Session.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Update方法的具体用法?C# Session.Update怎么用?C# Session.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Session的用法示例。


在下文中一共展示了Session.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateName

        /// <summary>
        /// 用户更新用户名
        /// </summary>
        /// <param name="session"></param>
        /// <param name="user"></param>
        /// <param name="newName"></param>
        /// <param name="currentAccountNo"></param>
        /// <returns></returns>
        public static bool UpdateName(Session session, User user, string newName, string currentAccountNo)
        {
            if (string.IsNullOrEmpty(newName)) throw new ArgumentNullException("newName");
            if (newName.Equals(user.Name)) return true;

            var account = session.Load<Account>(m => m.Name.Equals(user.Name));
            if(account == null) throw  new ArgumentException(string.Format("用户{0}不存在", user.Name), "user");

            account.Name = newName;
            user.Name = newName;

            return session.Update(user) &&
                   session.Update(account) &&
                   user.Deactive(session, currentAccountNo);
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:23,代码来源:UserService.cs

示例2: UpdateObjectDeltaThrowsObjectDisposedExceptionIfDisposed

        public void UpdateObjectDeltaThrowsObjectDisposedExceptionIfDisposed()
        {
            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                new Mock<IDbDriver>().Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new IUpdateListener[0]);

            using (session)
            {
            }

            Assert.Throws<ObjectDisposedException>(() => session.Update(new ObjectDelta(typeof(Customer), 1234)));
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:16,代码来源:SessionTests.cs

示例3: UpdateObjectDeltaThrowsMicroLiteExceptionIfItContainsNoChanges

        public void UpdateObjectDeltaThrowsMicroLiteExceptionIfItContainsNoChanges()
        {
            var objectDelta = new ObjectDelta(typeof(Customer), 1234);

            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                new Mock<IDbDriver>().Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new IUpdateListener[0]);

            var exception = Assert.Throws<MicroLiteException>(() => session.Update(objectDelta));

            Assert.Equal(ExceptionMessages.ObjectDelta_MustContainAtLeastOneChange, exception.Message);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:16,代码来源:SessionTests.cs

示例4: UpdateObjectDeltaReturnsTrueIfRecordUpdated

        public void UpdateObjectDeltaReturnsTrueIfRecordUpdated()
        {
            var objectDelta = new ObjectDelta(typeof(Customer), 1234);
            objectDelta.AddChange("Name", "Fred Flintstone");

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(objectDelta)).Returns(new SqlQuery(""));

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);

            var mockConnection = new Mock<IDbConnection>();
            mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);

            var session = new Session(
                ConnectionScope.PerTransaction,
                mockSqlDialect.Object,
                mockDbDriver.Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new IUpdateListener[0]);

            Assert.True(session.Update(objectDelta));

            mockDbDriver.VerifyAll();
            mockCommand.VerifyAll();
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:30,代码来源:SessionTests.cs

示例5: UpdateInstanceThrowsMicroLiteExceptionIfIdentifierNotSet

        public void UpdateInstanceThrowsMicroLiteExceptionIfIdentifierNotSet()
        {
            var customer = new Customer
            {
                Id = 0
            };

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.CreateConnection()).Returns(new Mock<IDbConnection>().Object);

            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                mockDbDriver.Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new IUpdateListener[0]);

            var exception = Assert.Throws<MicroLiteException>(() => session.Update(customer));

            Assert.Equal(ExceptionMessages.Session_IdentifierNotSetForUpdate, exception.Message);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:22,代码来源:SessionTests.cs

示例6: UpdateObjectDeltaReturnsFalseIfNoRecordUpdated

        public void UpdateObjectDeltaReturnsFalseIfNoRecordUpdated()
        {
            var objectDelta = new ObjectDelta(typeof(Customer), 1234);
            objectDelta.AddChange("Name", "Fred Flintstone");

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(0);
            mockCommand.As<IDisposable>().Setup(x => x.Dispose());

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(objectDelta)).Returns(new SqlQuery(""));

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
            mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);

            var session = new Session(
                ConnectionScope.PerTransaction,
                mockSqlDialect.Object,
                mockDbDriver.Object,
                new IListener[0]);

            Assert.False(session.Update(objectDelta));

            mockDbDriver.VerifyAll();
            mockCommand.VerifyAll();
        }
开发者ID:rubenalves,项目名称:MicroLite,代码行数:27,代码来源:SessionTests.cs

示例7: SaveNavigation

        private static long SaveNavigation(Session session, long navId, string moduelUrl)
        {
            var nav = session.Load<Navigation>(navId);
            if (nav == null) throw new ArgumentNullException("navId");

            nav.Url = moduelUrl;
            if (session.Update(nav)) { return nav.Id; }

            throw new Exception(string.Format("保存导航失败:Id - {0}, Name - {1}", nav.Id, nav.Name));
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:10,代码来源:SystemActivity.cs

示例8: UpdateInstanceThrowsArgumentNullExceptionForNullInstance

        public void UpdateInstanceThrowsArgumentNullExceptionForNullInstance()
        {
            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                new Mock<IDbDriver>().Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new IUpdateListener[0]);

            var exception = Assert.Throws<ArgumentNullException>(() => session.Update((Customer)null));

            Assert.Equal("instance", exception.ParamName);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:14,代码来源:SessionTests.cs

示例9: DeactiveAccount

 public bool DeactiveAccount(Session session, string currentAccountNo)
 {
     var account = session.Load<Account>(m => m.Name.Equals(Name));
     if (account == null)
     {
         account = new Account();
         account.Name = Name;
         account.Password = Guid.NewGuid().ToString();
         account.Status = Account.Inactive;
         account.CreatedAt = DateTime.Now;
         account.CreatedBy = currentAccountNo;
         return session.Create(account);
     }
     account.Status = Account.Inactive;
     account.UpdatedAt = DateTime.Now;
     account.UpdatedBy = currentAccountNo;
     return session.Update(account);
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:18,代码来源:User.cs

示例10: DeactiveAccount

 private bool DeactiveAccount(Session session, string currentAccountNo)
 {
     var account = session.Load<Account>(m => m.Name.Equals(Code));
     if (account == null)
     {
         account = new Account
             {
                 Name = Code,
                 Password = Guid.NewGuid().ToString(),
                 Status = Account.Inactive,
                 CreatedAt = DateTime.Now,
                 CreatedBy = currentAccountNo
             };
         return session.Create(account);
     }
     account.Flag = null;
     account.Status = Account.Inactive;
     account.UpdatedAt = DateTime.Now;
     account.UpdatedBy = currentAccountNo;
     return session.Update(account);
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:21,代码来源:User.cs

示例11: ActiveUser

 private bool ActiveUser(Session session, string currentAccountNo)
 {
     IsActive = true;
     UpdatedAt = DateTime.Now;
     UpdatedBy = currentAccountNo;
     return session.Update(this);
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:7,代码来源:User.cs

示例12: UpdateInstanceBuildsAndExecutesQuery

        public void UpdateInstanceBuildsAndExecutesQuery()
        {
            var customer = new Customer
            {
                Id = 187224
            };

            var rowsAffected = 1;

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(rowsAffected);

            var mockConnection = new Mock<IDbConnection>();
            mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);

            var session = new Session(
                ConnectionScope.PerTransaction,
                mockSqlDialect.Object,
                mockDbDriver.Object,
                new SessionListeners());

            session.Update(customer);

            mockSqlDialect.VerifyAll();
            mockDbDriver.VerifyAll();
            mockCommand.VerifyAll();
        }
开发者ID:TrevorPilley,项目名称:MicroLite,代码行数:33,代码来源:SessionTests.cs

示例13: UpdateObjectDeltaThrowsArgumentNullExceptionForNullObjectDelta

        public void UpdateObjectDeltaThrowsArgumentNullExceptionForNullObjectDelta()
        {
            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                new Mock<IDbDriver>().Object,
                new SessionListeners());

            var exception = Assert.Throws<ArgumentNullException>(() => session.Update((ObjectDelta)null));

            Assert.Equal("objectDelta", exception.ParamName);
        }
开发者ID:TrevorPilley,项目名称:MicroLite,代码行数:12,代码来源:SessionTests.cs

示例14: UpdateInstanceThrowsObjectDisposedExceptionIfDisposed

        public void UpdateInstanceThrowsObjectDisposedExceptionIfDisposed()
        {
            var session = new Session(
                ConnectionScope.PerTransaction,
                new Mock<ISqlDialect>().Object,
                new Mock<IDbDriver>().Object,
                new SessionListeners());

            using (session)
            {
            }

            Assert.Throws<ObjectDisposedException>(() => session.Update(new Customer()));
        }
开发者ID:TrevorPilley,项目名称:MicroLite,代码行数:14,代码来源:SessionTests.cs

示例15: UpdateInstanceInvokesListeners

        public void UpdateInstanceInvokesListeners()
        {
            var customer = new Customer
            {
                Id = 187224
            };

            var rowsAffected = 1;

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(rowsAffected);

            var mockConnection = new Mock<IDbConnection>();
            mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);

            int counter = 0;

            var mockListener1 = new Mock<IUpdateListener>();
            mockListener1.Setup(x => x.AfterUpdate(customer, 1)).Callback(() => Assert.Equal(4, ++counter));
            mockListener1.Setup(x => x.BeforeUpdate(customer)).Callback(() => Assert.Equal(1, ++counter));

            var mockListener2 = new Mock<IUpdateListener>();
            mockListener2.Setup(x => x.AfterUpdate(customer, 1)).Callback(() => Assert.Equal(3, ++counter));
            mockListener2.Setup(x => x.BeforeUpdate(customer)).Callback(() => Assert.Equal(2, ++counter));

            var session = new Session(
                ConnectionScope.PerTransaction,
                mockSqlDialect.Object,
                mockDbDriver.Object,
                new IDeleteListener[0],
                new IInsertListener[0],
                new[] { mockListener1.Object, mockListener2.Object });

            session.Update(customer);

            mockListener1.VerifyAll();
            mockListener2.VerifyAll();
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:44,代码来源:SessionTests.cs


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