Setting Deleted constraints

Original Post Tommy's Avatar

Tommy

14 Jun, 2010 02:12 PM via web

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

  1. 2 Posted by Tommy on 17 Jun, 2010 11:44 AM

    Tommy's Avatar

    Any ideas on this? I think it might be relatively simple just hard to know what to do!

    Cheers again,

    Tommy

  2. Support Staff 3 Posted by Paul Batum on 17 Jun, 2010 12:47 PM

    Paul Batum's Avatar

    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:

  3. Support Staff 4 Posted by Paul Batum on 19 Jun, 2010 06:16 AM

    Paul Batum's Avatar

    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.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What day comes after Monday?

    Recent Discussions

    05 Jul, 2010 10:29 PM
    05 Jul, 2010 12:45 PM
    05 Jul, 2010 12:42 PM
    05 Jul, 2010 12:17 PM
    05 Jul, 2010 12:12 PM

     

    03 Jul, 2010 12:26 AM
    02 Jul, 2010 02:17 PM
    02 Jul, 2010 08:18 AM
    02 Jul, 2010 12:20 AM
    01 Jul, 2010 10:14 PM