2017-06-07 38 views
0

我的Web應用程序不時會開始拋出以下錯誤。NHibernate和MySql丟失列例外

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

+0

能否請您提供的代碼片段?那麼只有我們可以幫助你。 – Naruto

回答

0

好了這個問題。它是因爲你在準備好的聲明中傳遞的一些論據是空的,那就是爲什麼這個錯誤。我以前有過類似的問題,我通過檢查它是否爲空來將它添加到查詢過濾中來解決它。

另外還有另一種可能性是由任何其他查詢進行行鎖定。你在MySQL查詢中使用鎖嗎?

第二個問題似乎看到了解決方案說明如下

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

+0

查詢中沒有內容爲空。我發送了幾個常量,並根據記錄的查詢將一個動態值附加爲參數。 – cangerer