1
votes

Here's the (edited) domain class:

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; }
  ...
}

Here's the Fluent mapping:

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

I don't map LastName in Patient. The table has a LastName column (a varbinary) and no LastNameEncrypted column.

Here's the query:

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();
} 

The return (inside the if block) is where the error is triggered. The error says "Could not resolve property LastName of Patient".

I am using NHibernate (v2.1.2.4000), Fluent NHibernate (v1.1.0.685) and NHibernate.Linq (v1.1.0.1001). I cannot update these DLLs.

Is it because I don't have a mapping for Patient.LastName? I don't have or need one. If that is the issue, how do I map/tell Fluent NHibernate to ignore that property?

PS: I am not using AutoMapping, only explicit mappings. They are loaded as follows. In my application, only cfg (an NHibernate.Cfg.Configuration object) and mappingAssemblies (which points to the one DLL with the mappings) have a value.

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();
}
1
Where does the error come from? Does a query throw the exception?rumpelstiefel
Right. Edited question to answer that necessary and overlooked part of problem.alphadogg
I assume, that this.MatchingCriteria causes the problem. Could you please show the content of MatchingCriteria?rumpelstiefel

1 Answers

0
votes

This error happens when you do the query. Looking to your code I see only one thing that might cause the problem - that is MatchingCriteria:

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

What type is stored in this.MatchingCriteria?

Try to replace it with inline conditions: in

..Where(<put_inline_criteria_here>)..