As I posted on stackoverflow 
<http://stackoverflow.com/questions/26613328/nhibernate-many-to-one-filter-in-mapping-where-clause-references-wrong-table>,
 
I will post it here to have a bit more visibility:

In my project structure, I am using a Table-per-class hierarchy and I am 
having an issue with a filter that in some case will look for a property 
that is in a superclass. When that case happens, the sql generated by 
NHibernate uses the wrong alias to look for the property. In the database, 
the column is in the parent table, but the alias used is for the child 
table.

Simple structure to get to the point:


public class Animal{
    public virtual int Id { get; set; }
    public virtual Owner Owner { get; set; }
    public virtual string Name { get; set; }}
public class Dog: Animal{
    public virtual string Color { get; set; }}
public class Owner{
    public virtual int Id { get; set; }

    public IList<Dog> Dogs { get; set; }}
public class AnimalMap: ClassMap<Animal>{
    public AnimalMap(){
        Table("Animals");
        Id(x => x.Id);

        References(x => x.Owner, "OwnerId");

        Map(x => x.Name);
    }}
public class DogMap: SubClassmap<Dog>{
    public DogMap(){
        Table("Dogs");

        Map(x => x.Name);
    }}
public class OwnerMap: ClassMap<Owner>{
    public AnimalMap(){
        Table("Animals");
        Id(x => x.Id);

        HasMany(x => x.Dogs)
        .ApplyFilter<AnimalNameFilter>()
        .AsBag();
    }}
public class AnimalNameFilter: FilterDefinition{
    public const string FilterName = "AnimalNameFilter";
    public IsAllowedFilter()
    {
        // stored function from the database
        WithName(FilterName)
            .WithCondition("dbo.IsAnimalNameValid(Name) = 1");
    }}


In this example, the problem is that my query will generate a join between 
the tables Animals and Dogs, but the filter will try to look for the column 
Name in the table Dogs instead of Animals.

What am I doing wrong and how can I fix this?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to