2013-01-19 64 views
1

這裏是(編輯)域類:流利的NHibernate的錯誤:「無法解析屬性」

public class Patient : IntegerKeyEntity 
{ 
    ... 
    public virtual string LastName 
    { 
     get 
     { 
      return Encoding.Unicode.GetString(encryptionService.Decrypt(LastNameEncrypted)); 
     } 
     set 
     { 
      LastNameEncrypted = encryptionService.Encrypt(value); 
     } 
    } 
    /// <summary> 
    /// Contains the encrypted last name. Access via LastName for unencrypted version. 
    /// </summary> 
    public virtual byte[] LastNameEncrypted { get; set; } 
    ... 
} 

這裏的流利映射:

public class PatientMap : ClassMap<Patient> 
{ 
    public PatientMap() 
    { 
    ... 
    Map(x => x.LastNameEncrypted, "LastName") 
     .Not.Nullable(); 
    ... 
    } 
} 

我不耐心映射姓氏。該表有一個LastName列(varbinary),沒有LastNameEncrypted列。

這裏的查詢:

public virtual IQueryable<TResult> SatisfyingElementsFrom(IQueryable<T> candidates, int start, int limit, string sort, string dir) 
{ 
    if (this.MatchingCriteria != null) 
    { 
     return candidates.Where(this.MatchingCriteria).OrderBy(sort + " " + dir).Skip(start).Take(limit).ToList().ConvertAll(this.ResultMap).AsQueryable(); 
    } 

    return candidates.ToList().ConvertAll(this.ResultMap).AsQueryable(); 
} 

回報(if塊內)是其中被觸發的錯誤。錯誤顯示「無法解析患者的姓氏姓氏」。

我使用NHibernate(v2.1.2.4000),功能NHibernate(v1.1.0.685)和NHibernate.Linq(v1.1.0.1001)。我無法更新這些DLL。

是因爲我沒有Patient.LastName的映射嗎?我沒有或沒有需要。如果這是問題,我該如何映射/告訴Fluent NHibernate忽略該屬性?

PS:我沒有使用AutoMapping,只顯式映射。它們的加載如下。在我的應用程序中,只有cfg(一個NHibernate.Cfg.Configuration對象)和mappingAssemblies(指向具有映射的一個DLL)有一個值。

private static ISessionFactory CreateSessionFactoryFor(string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) 
{ 
    FluentConfiguration fluentConfiguration = Fluently.Configure(cfg); 

    if (persistenceConfigurer != null) 
    { 
     fluentConfiguration.Database(persistenceConfigurer); 
    } 

    fluentConfiguration.Mappings(m => 
    { 
     foreach (var mappingAssembly in mappingAssemblies) 
     { 
      var assembly = Assembly.LoadFrom(MakeLoadReadyAssemblyName(mappingAssembly)); 

      m.HbmMappings.AddFromAssembly(assembly); 
      m.FluentMappings.AddFromAssembly(assembly).Conventions.AddAssembly(assembly); 
     } 

     if (autoPersistenceModel != null) 
     { 
      m.AutoMappings.Add(autoPersistenceModel); 
     } 

    }); 

    return fluentConfiguration.BuildSessionFactory(); 
} 
+0

哪裏從何而來的錯誤?查詢是否拋出異常? – rumpelstiefel

+0

對。編輯問題以回答問題的必要和被忽視的部分。 – alphadogg

+0

我假定,this.MatchingCriteria引起該問題。你能否展示MatchingCriteria的內容? – rumpelstiefel

回答

0

當您執行查詢時會發生此錯誤。展望你的代碼,我看到的只有一兩件事,可能引起的問題 - 那就是MatchingCriteria:

return candidates.Where(this.MatchingCriteria)... 

什麼類型存儲在this.MatchingCriteria?

嘗試使用內嵌的條件來替代它:在

..Where(<put_inline_criteria_here>).. 
相關問題