【问题标题】:NHibernate and MySql Missing column ExceptionNHibernate 和 MySql 缺少列异常
【发布时间】:2023-03-07 22:08:01
【问题描述】:

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

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

【问题讨论】:

  • 能否提供代码sn-p?那么只有我们可以帮助您。

标签: c# mysql nhibernate


【解决方案1】:

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

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

第二个问题似乎见下文所述的解决方案

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

【讨论】:

  • 查询中没有任何内容为空。我发送了几个常量,并根据记录的查询附加了一个动态值作为参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 2010-10-17
  • 2020-01-05
  • 2021-02-12
相关资源
最近更新 更多