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


C# Session.Delete方法代码示例

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


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

示例1: DeleteInstanceInvokesListeners

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

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildDeleteSqlQuery(It.IsNotNull<IObjectInfo>(), customer.Id)).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);

            int counter = 0;

            var mockListener1 = new Mock<IDeleteListener>();
            mockListener1.Setup(x => x.AfterDelete(customer, 1)).Callback(() => Assert.Equal(4, ++counter));
            mockListener1.Setup(x => x.BeforeDelete(customer)).Callback(() => Assert.Equal(1, ++counter));

            var mockListener2 = new Mock<IDeleteListener>();
            mockListener2.Setup(x => x.AfterDelete(customer, 1)).Callback(() => Assert.Equal(3, ++counter));
            mockListener2.Setup(x => x.BeforeDelete(customer)).Callback(() => Assert.Equal(2, ++counter));

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

            session.Delete(customer);

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

示例2: RegisterNavigation

        /// <summary>
        /// 注册导航
        /// </summary>
        /// <param name="session"></param>
        /// <param name="container">导航分类容器</param>
        internal void RegisterNavigation(Session session, NavigationContainer container)
        {
            var moduleOrderDict = new Dictionary<string, int>();
            AddModuleOrder(container.Categories, moduleOrderDict);

            var assembly = typeof(SystemActivity).Assembly;

            foreach (var type in assembly.GetExportedTypes())
            {
                if (type == null) continue;
                if (!type.FullName.EndsWith("Controller")) continue;

                var categoryAttrs = GetCategoryAttributes(type);
                if (categoryAttrs == null)
                {
                    _logger.Warn("{0}没有CategoryAttribute标记", type.FullName);
                    continue;
                }

                var moduleAttr = GetModuleAttribute(type);
                if (moduleAttr == null)
                {
                    _logger.Warn("{0}没有ModuleAttribute标记", type.FullName);
                    continue;
                }

                _logger.Info("处理控制器 {0}", type.FullName);

                var area = GetArea(type);

                // 隐藏
                if (categoryAttrs.Any(m => m.HideMenu)) continue;

                var categoryId = SaveNavigationCategory(session, categoryAttrs);

                var moduleOrderId = string.IsNullOrEmpty(moduleAttr.Name) ? 0 :
                    moduleOrderDict.ContainsKey(moduleAttr.Name) ? moduleOrderDict[moduleAttr.Name] : 0;

                var moduleId = SaveNavigation(session, moduleAttr, categoryId , moduleOrderId, type.Name.Replace("Controller", ""));
                var hasNormalMoudle = !string.IsNullOrEmpty(moduleAttr.Name);
                var foundDefaultModuleAction = false;

                var controller = type.Name.Replace("Controller", String.Empty);

                var validMethodsCount = 0;

                foreach (var mi in type.GetMethods())
                {
                    var action = mi.Name;
                    _logger.Debug("process Controller {0} Actioon {1}", controller, action);

                    // 更新模块的URL
                    if (hasNormalMoudle && !foundDefaultModuleAction && moduleAttr.DefaultAction != null && action.Equals(moduleAttr.DefaultAction))
                    {
                        foundDefaultModuleAction = true;
                        SaveNavigation(session, moduleId, GetUrl(area, controller, action));
                        continue;
                    }

                    var attr = GetPriviledgeAttribute(mi);
                    if (attr == null) continue;

                    if (!attr.NotCheck) validMethodsCount++;
                    SaveNavigation(session, attr, moduleId, area, controller, action);
                }

                if (validMethodsCount == 0)
                {
                    var count = session.Count<Navigation>(m => m.ParentId.Equals(categoryId));
                    if (count == 0)
                    {
                        if (!session.Delete<Navigation>(m => m.Id.Equals(categoryId))) throw new Exception("删除数据分类失败");
                    }
                }
                else
                {
                    var nav = session.Load<Navigation>(moduleId);
                    nav.AuthCode = Navigation.ShouldCheck;
                    if (!session.Update(nav)) throw new Exception("更新数据模块[NotCheck]失败");

                    if (moduleId != categoryId)
                    {
                        nav = session.Load<Navigation>(categoryId);
                        nav.AuthCode = Navigation.ShouldCheck;
                        if (!session.Update(nav)) throw new Exception("更新数据分类[NotCheck]失败");

                    }

                }
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:96,代码来源:SystemActivity.cs

示例3: DeleteInstanceReturnsFalseIfNoRecordsDeleted

        public void DeleteInstanceReturnsFalseIfNoRecordsDeleted()
        {
            var customer = new Customer
            {
                Id = 14556
            };

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

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

            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.False(session.Delete(customer));

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

示例4: DeleteTypeByIdentifierThrowsObjectDisposedExceptionIfDisposed

        public void DeleteTypeByIdentifierThrowsObjectDisposedExceptionIfDisposed()
        {
            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.Delete(typeof(Customer), 1234));
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:16,代码来源:SessionTests.cs

示例5: DeleteTypeByIdentifierThrowsMicroLiteExceptionIfExecuteNonQueryThrowsException

        public void DeleteTypeByIdentifierThrowsMicroLiteExceptionIfExecuteNonQueryThrowsException()
        {
            var type = typeof(Customer);
            var identifier = 1234;

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

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Throws<InvalidOperationException>();

            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]);

            var exception = Assert.Throws<MicroLiteException>(() => session.Delete(type, identifier));

            Assert.NotNull(exception.InnerException);
            Assert.Equal(exception.InnerException.Message, exception.Message);

            // Command should still be disposed.
            mockCommand.VerifyAll();
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:33,代码来源:SessionTests.cs

示例6: DeleteTypeByIdentifierThrowsArgumentNullExceptionForNullType

        public void DeleteTypeByIdentifierThrowsArgumentNullExceptionForNullType()
        {
            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.Delete(null, 1234));

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

示例7: DeleteTypeByIdentifierReturnsTrueIfRecordDeleted

        public void DeleteTypeByIdentifierReturnsTrueIfRecordDeleted()
        {
            var type = typeof(Customer);
            var identifier = 1234;

            var mockSqlDialect = new Mock<ISqlDialect>();
            mockSqlDialect.Setup(x => x.BuildDeleteSqlQuery(It.IsNotNull<IObjectInfo>(), identifier)).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.Delete(type, identifier));

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

示例8: DeleteTypeByIdentifierReturnsFalseIfNoRecordsDeleted

        public void DeleteTypeByIdentifierReturnsFalseIfNoRecordsDeleted()
        {
            var type = typeof(Customer);
            var identifier = 1234;

            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.BuildDeleteSqlQuery(It.IsNotNull<IObjectInfo>(), identifier)).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.Delete(type, identifier));

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

示例9: DeleteInstanceThrowsMicroLiteExceptionIfIdentifierNotSet

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

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

            var mockDbDriver = new Mock<IDbDriver>();
            mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.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.Delete(customer));

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

示例10: Delete

 public bool Delete(Session session)
 {
     var account = session.Load<Account>(m => m.Name.Equals(Name));
     if (account == null)
     {
         return true;
     }
     if (!session.Delete<AccountNavigationRef>(m => m.Type.Equals(AccountNavigationRef.AccountType) && m.OwnerId.Equals(account.Id)))
     {
         return false;
     }
     if (!session.Delete<AccountRoleRef>(m => m.AccountId.Equals(account.Id)))
     {
         return false;
     }
     if (!session.Delete<User>(m => m.Id.Equals(Id)))
     {
         return false;
     }
     return true;
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:21,代码来源:User.cs

示例11: DeleteTypeByIdentifierThrowsArgumentNullExceptionForNullIdentifier

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

            var exception = Assert.Throws<ArgumentNullException>(() => session.Delete(typeof(Customer), null));

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

示例12: DeleteInstanceThrowsMicroLiteExceptionIfExecuteNonQueryThrowsException

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

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

            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(x => x.ExecuteNonQuery()).Throws<InvalidOperationException>();

            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());

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

            Assert.NotNull(exception.InnerException);
            Assert.Equal(exception.InnerException.Message, exception.Message);

            // Command should still be disposed.
            mockCommand.VerifyAll();
        }
开发者ID:TrevorPilley,项目名称:MicroLite,代码行数:33,代码来源:SessionTests.cs

示例13: DeleteInstanceThrowsArgumentNullExceptionForNullInstance

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

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

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

示例14: CreateStudentClassTransactionTrackingData

        public static XPCollection<AccountTransactionTracking> CreateStudentClassTransactionTrackingData(Session session, string classCode, string semesterName)
        {
            try
            {
                using (XPCollection<AccountTransactionTracking> xpw = new XPCollection<AccountTransactionTracking>(session,
                               new BinaryOperator("Student.StudentClass.ClassCode", classCode)))
                {
                    session.Delete(xpw);
                    session.CommitTransaction();

                    StudentClass studentClass = session.FindObject<StudentClass>(
                        new BinaryOperator("ClassCode", classCode));
                    Semester semester = session.FindObject<Semester>(
                        new BinaryOperator("SemesterName", semesterName));
                    DateTime semesterLastDate = semester.StartDate.AddDays(semester.NumberOfWeek * 7);

                    decimal beforedebtvalue = 0;
                    decimal requestvalue = 0;
                    decimal paidvalue = 0;

                    if (studentClass != null && semester != null)
                    {
                        //NestedUnitOfWork UOW = session.BeginNestedUnitOfWork();
                        //UOW.BeginTransaction();
                        foreach (Student student in studentClass.Students)
                        {
                            beforedebtvalue = 0;
                            requestvalue = 0;
                            paidvalue = 0;
                            foreach (AccountTransaction accTrans in student.AccountTransactions)
                            {
                                if ((accTrans.Semester != null &&
                                    Convert.ToInt32(accTrans.Semester.SemesterName) < Convert.ToInt32(semester.SemesterName)))
                                    //||accTrans.TransactingDate < semester.StartDate)

                                    beforedebtvalue += accTrans.MoneyAmount;

                                else if ((accTrans.Semester != null && accTrans.Semester.SemesterName == semester.SemesterName))
                                    //||accTrans.TransactingDate <= semesterLastDate )
                                {
                                    if (accTrans.MoneyAmount < 0) //money has to paid
                                    {
                                        requestvalue += (-accTrans.MoneyAmount);
                                    }
                                    else //money has paid
                                    {
                                        paidvalue += accTrans.MoneyAmount;
                                    }
                                }
                            }

                            AccountTransactionTracking accTracking = new AccountTransactionTracking(session);
                            accTracking.Student = student;
                            accTracking.Semester = semester;
                            accTracking.BeforeDebtValue = - beforedebtvalue;
                            accTracking.PaidValue = paidvalue;
                            accTracking.RequestValue = requestvalue;
                            accTracking.Save();
                        }
                        //UOW.CommitTransaction();
                        session.CommitTransaction();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("Lỗi thực hiện: " + ex.Message);
            }
            return new XPCollection<AccountTransactionTracking>(session,
                       new BinaryOperator("Student.StudentClass.ClassCode", classCode));
        }
开发者ID:dedangkyphanmem,项目名称:vidodkmh,代码行数:71,代码来源:Utilities.cs

示例15: DeleteInstanceThrowsObjectDisposedExceptionIfDisposed

        public void DeleteInstanceThrowsObjectDisposedExceptionIfDisposed()
        {
            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.Delete(new Customer()));
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:16,代码来源:SessionTests.cs


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