gpt4 book ai didi

c# - NHibernate 和 MySql 缺少列异常

转载 作者:行者123 更新时间:2023-11-29 18:49:35 24 4
gpt4 key购买 nike

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

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

最佳答案

好的,有问题了。这是因为您在准备好的声明中传递的某些参数为空,这就是此错误的原因。我之前遇到过类似的问题,我通过仅检查它是否为空将其添加到查询过滤中来解决它。

此外,任何其他查询还存在另一种行锁定的可能性。你在mysql查询中使用锁吗?

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

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

关于c# - NHibernate 和 MySql 缺少列异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44419308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com