1

我在我的应用程序中使用 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;
4

1 回答 1

2

FirebirdClientDriver并且FirebirdDriver两者都不支持多查询

如果您有多个 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)
于 2012-05-04T09:46:33.780 回答