NHibernate.Driver.FirebirdClientDriver不支持多个查询

时间:2012-05-02 16:46:21

标签: c# nhibernate

我在我的应用程序中使用nhibernate作为orm而使用firebird作为数据库。 目前正在尝试使用电子邮件提供商,但我有以下错误消息

The driver NHibernate.Driver.FirebirdClientDriver does not support multiple queries.

我的测试方法有以下代码

#region Test FindUserByEmail
        [Test]
        public void FindUserByEmail()
        { 
            //Arrange
            var email = "jamesbond@mi6.uk";
            var recs = -1;
            var expectedRecords = 1;

            //Act
            var actual = _provider.FindUsersByEmail(email, 0, 99, out recs);
            //Assert
            Assert.AreEqual(expectedRecords, recs);
            Assert.AreEqual(expectedRecords, actual.Count);
        }
        #endregion

是否存在nhibernate firebird驱动程序接受多个查询的解决方案?

更新添加了FindUsersByEmail方法

public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            CheckParameter(ref emailToMatch, false, false, false, 100, "emailToMatch");

            if (pageIndex < 0)
            {
                throw new ArgumentException("The pageIndex must be greater than or equal to zero.", "PageIndex");
            }
            if (pageSize < 1)
            {
                throw new ArgumentException("The pageSize must be greater than zero.", "pageSize");
            }

            long upperBound = (long)pageIndex * pageSize + pageSize - 1;
            if (upperBound > Int32.MaxValue)
            {
                throw new ArgumentException("The combination of pageIndex and pageSize cannot exceed the maximum value of System.Int32.", "pageIndex and pageSize");
            }

            totalRecords = 0;
            MembershipUserCollection users = new MembershipUserCollection();
            IList results;
            using (ISession session = SessionProvider.Instance.OpenSession())
            {
                using (ITransaction tran = session.BeginTransaction())
                {


                    results = session.CreateMultiCriteria()
                                        .Add(session.CreateCriteria(typeof(User)).Add(Restrictions.Like("UpperEmail", emailToMatch.ToUpper())).SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize))
                                        .Add(session.CreateCriteria(typeof(User)).Add(Restrictions.Like("UpperEmail", emailToMatch.ToUpper())).SetProjection(Projections.RowCountInt64()))
                                        .List();
                    tran.Commit();
                }
            }
            var dbUsers = (List<User>)results[0];
            totalRecords = (int)results[1];
            foreach (User u in dbUsers)
            {
                users.Add(new MembershipUser(Name,
                               u.UserName,
                               u.Id,
                               u.EMail,
                               u.PasswordQuestion,
                               u.Comment,
                               u.IsApproved,
                               u.IsLockedOut,
                               u.CreationDate,
                               GetNullableDateTime(u.LastLoginDate),
                               GetNullableDateTime(u.LastActivityDate),
                               GetNullableDateTime(u.LastPasswordChangeDate),
                               GetNullableDateTime(u.LastLockedOutDate)));
            }
            return users;

1 个答案:

答案 0 :(得分:2)

FirebirdClientDriverFirebirdDriver都不支持多查询

如果您有多个rdbms支持,我建议使用Futures而不是MultiCriteria,因为如果不支持多个查询,它们会自动回退到正常查询

示例:

var userquery = session.CreateCriteria(typeof(User))
    .Add(Restrictions.Like("UpperEmail", emailToMatch.ToUpper()))
    .SetFirstResult(pageIndex * pageSize)
    .SetMaxResults(pageSize);

var totalcountQuery = CriteriaTransformer.Clone(userquery)
    .SetProjection(Projections.RowCountInt64()));

IEnumerable<User> dbUsers = userquery.Future<User>();

IFutureValue<long> count = totalcountQuery.FutureValue<long>();

totalcount = count.Value;  // both will be executed here
foreach ( User u in dbUsers)