NHibernate和MySql缺少列Exception

时间:2017-06-07 17:35:00

标签: c# mysql nhibernate

我的网络应用程序有时会开始抛出以下错误。

使用NHibernate 4.0.0.4000和MySql.Data 6.8.3

堆栈跟踪
ERROR [(null)] - Message:could not execute query

NHibernate日志
NHibernate.Util.ADOExceptionReporter WARN - System.IndexOutOfRangeException: Could not find specified column in results:

一旦发生这些错误,它就会经常开始,直到Web应用程序重新启动。

奇怪的是,它只发生在一些用户而不是全部用户身上。我还注意到在这个特定的日志消息中应该交换p4和p5的值。

这是查询缓存的问题吗?

有没有人对这种情况发生的原因有所了解?

如果它有帮助,那就是粗糙的查询(但我在更简单的查询中也看到了这个错误)

FunderInfoViewModel funderDto = null;
Funder funderAlias = null;
Contact contactAlias = null;

var totalOpportunitiesAwardedCount = QueryOver.Of<Opportunity>()
                .Where(o => o.Funder.Id == funderAlias.Id)
                .And(o => o.Status == OpportunityStatus.Awarded || o.Status == OpportunityStatus.AwardedClosed)
                .SelectList(list => list
                    .SelectCount(o => o.Id));

            var totalOpportunitiesAwardedSum = QueryOver.Of<Opportunity>()
                .Where(o => o.Funder.Id == funderAlias.Id)
                .And(o => o.Status == OpportunityStatus.Awarded || o.Status == OpportunityStatus.AwardedClosed)
                .SelectList(list => list
                    .SelectSum(o => o.AmountAwarded));

            var totalOpportunitiesCount = QueryOver.Of<Opportunity>()
                .Where(o => o.Funder.Id == funderAlias.Id)
                .SelectList(list => list
                    .SelectCount(o => o.Id));

            IEnumerable<FunderInfoViewModel> funders = _session.QueryOver(() => funderAlias)
                .Left.JoinAlias(f => f.Contacts, () => contactAlias, x => x.IsDefault)
                .Where(o => o.Organization.Id == organizationId)
                .SelectList(list => list
                    .Select(x => x.Id)
                    .WithAlias(() => funderDto.Id)
                    .Select(x => x.Name)
                    .WithAlias(() => funderDto.Name)
                    .Select(x => x.Description)
                    .WithAlias(() => funderDto.Description)
                    .Select(x => x.AreasOfInterest)
                    .WithAlias(() => funderDto.AreasOfInterest)
                    .Select(x => x.Type)
                    .WithAlias(() => funderDto.FunderType)
                    .Select(x => x.TaxId)
                    .WithAlias(() => funderDto.TaxId)
                    .Select(x => x.PhoneNumber)
                    .WithAlias(() => funderDto.PhoneNumber)
                    .Select(x => x.FaxNumber)
                    .WithAlias(() => funderDto.FaxNumber)
                    .Select(x => x.EmailAddress)
                    .WithAlias(() => funderDto.EmailAddress)
                    .Select(x => x.Website)
                    .WithAlias(() => funderDto.Website)
                    .Select(x => x.CustomLink)
                    .WithAlias(() => funderDto.CustomLink)
                    .Select(x => x.MinimumFundingRange)
                    .WithAlias(() => funderDto.MinimumFundingRange)
                    .Select(x => x.MaximumFundingRange)
                    .WithAlias(() => funderDto.MaximumFundingRange)
                    .Select(() => contactAlias.FirstName)
                    .WithAlias(() => funderDto.PrimaryContactFirstName)
                    .Select(() => contactAlias.LastName)
                    .WithAlias(() => funderDto.PrimaryContactLastName)
                    .Select(() => contactAlias.Title)
                    .WithAlias(() => funderDto.PrimaryContactTitle)
                    .SelectSubQuery(totalOpportunitiesAwardedCount)
                    .WithAlias(() => funderDto.AwardedOpportunitiesCount)
                    .SelectSubQuery(totalOpportunitiesAwardedSum)
                    .WithAlias(() => funderDto.AwardedOpportunitiesValue)
                    .SelectSubQuery(totalOpportunitiesCount)
                    .WithAlias(() => funderDto.OpportunitiesCount)
                )
                .OrderBy(f => f.Name)
                .Asc
                .TransformUsing(Transformers.AliasToBean<FunderInfoViewModel>())
                .List<FunderInfoViewModel>();

1 个答案:

答案 0 :(得分:0)

好的问题了。因为你在准备好的语句中传递的一些争论是空的,这就是为什么这个错误。我之前有过类似的问题,我通过检查它是否为空来解决它,在查询过滤中添加它。

还有另一种可能由任何其他查询进行行锁定。你在mysql查询中使用锁吗?

第二个问题似乎看到下面提到的解决方案

https://forums.asp.net/t/1230295.aspx?IDataReader+Could+not+find+specified+column+in+results+