views:

23

answers:

1

I use a Where clause in my FluentNHibernate mappings as follows:

public class FooMap : ClassMap<Foo>
{
  public FooMap()
  {
    Table("MySchema.Foos");
    Where("Deleted = 0");
    etc etc
  }
}

This where clause gets appended to the SQL when I load individual Foo instances through session.Load<Foo>(1) and when I use LINQ queries. However, if another class has a collection of Foos and I iterate through the collection, the SQL generated to load the Foos does NOT contain the where clause.

Is this a bug in FluentNHibernate, or NHibernate in general? Or am I doing something wrong? Or is it (shudder) a 'feature'?

A: 

It's a fact, I don't know if it's a bug, a feature, or a missing feature. I ran into the same issue with a legacy database, although mine was with a many-to-one relationship (a "god" lookup table).

I think the justification is that once the foreign-key relationship has been established then the where clause has no meaning. For soft delete tables, look into using filters or (my preference) map to a view that filters the deleted records, assuming they don't need to appear in the UI.

Jamie Ide
Thanks for your response. I haven't looked into filters and didn't know you could map to a view - I'll take a look! Thanks.
David