Setting Deleted constraints
Hello,
I'm using Fluent NHibernate w/ Automapping and I want to make it so that each database table I have has a boolean column named "Deleted" and if something is set as Deleted then it will not appear at all on NHibernate requests.
To this end I have created three conventions, taking IOneToOneInstance, IOneToManyCollectionInstance and IManyToManyCollectionInstance. For the IOneToManyCollectionInstance I have put:
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Where("Deleted = 0");
instance.Cascade.SaveUpdate();
}
and this works well but IOneToOneInstance does not have a .Where so how would I make it so Deleted objects would not appear on One-to-One relationships?
Also, I tried using the .Where on the IManyToManyCollectionInstance but this tried to check whether the link-table for the many-to-many had the Deleted which was not what I was after. How, in this case, would I achieve my aims?
Thanks in advance,
Tommy
2 Posted by Tommy on 17 Jun, 2010 11:44 AM
Any ideas on this? I think it might be relatively simple just hard to know what to do!
Cheers again,
Tommy
Support Staff 3 Posted by Paul Batum on 17 Jun, 2010 12:47 PM
If you look at the NH xml schema, 'where' doesn't exist for one-to-one
mappings, so theres no support for it.
Regarding the problem with your where clause for the many-to-many, I think
you need to use "ChildWhere", which isn't exposed on the conventions yet. I
created a ticket<http://fluentnhibernate.lighthouseapp.com/projects/33236/tickets/185-add-convention-support-for-where-childwhere-and-other-relevant-mappings>for
myself to remind me to do it this weekend:
Support Staff 4 Posted by Paul Batum on 19 Jun, 2010 06:16 AM
Hi Tommy,
I'm actually quite confused by your post now.
IManyToManyCollectionInstance doesn't
have a Where method, nor does the IRelationshipInstance that you can access
using the Relationship property. It should have that method, and I've just
added it, but I am really having trouble understanding whats going on.
Putting aside my confusion, I think you want to use the .Where method
on ICollectionInstance
as that should apply to the child table rather than the joining table.