Eager fetching in [ARFetch]

1 view
Skip to first unread message

Fábio Batista

unread,
Apr 19, 2007, 5:46:29 PM4/19/07
to Castle Developers
Guys,

Eager fetching in [ARFetch]: My first real contribution in the last
months, since I've been busy a lot.

The usage is:

public void ShowPosts([ARFetch(Eager = "Posts")] Blog blog) { ... }

It's useful when you know that you'll iterate through a lazy
collection in an specific action, and want to save the database
roundtrip without hacking your mappings.

Ayende,

Can you check the changes on r3723? Is that the best way to perform
eager fetching when loading an object?

I'm pasting the relevant code:

// load using eager fetching of lazy collections
DetachedCriteria criteria = DetachedCriteria.For(type);
criteria.Add(Expression.Eq(pkModel.Property.Name, convertedPk));
foreach (string associationToEagerFetch in attr.Eager.Split(','))
{
string clean = associationToEagerFetch.Trim();
if (clean.Length == 0)
continue;

criteria.SetFetchMode(clean, FetchMode.Eager);
}

object[] result = (object[]) ActiveRecordMediator.FindAll(type, criteria);
if (result.Length > 0)
instance = result[0];

--
Fábio David Batista
fabio.dav...@gmail.com
http://nerd-o-matic.blogspot.com

Hamilton Verissimo

unread,
Apr 19, 2007, 7:41:03 PM4/19/07
to castle-pro...@googlegroups.com
Great. Well done!!


--
Cheers,
hamilton verissimo
ham...@castlestronghold.com
http://www.castlestronghold.com/

Ayende Rahien

unread,
Apr 20, 2007, 2:36:10 AM4/20/07
to castle-pro...@googlegroups.com
Yes, that is the way to do it. I think that Eager was deprecated in favor of Join, though.

On 4/20/07, Fábio Batista < fabio.dav...@gmail.com> wrote:

Guys,

Eager fetching in [ARFetch]: My first real contribution in the last
months, since I've been busy a lot.

The usage is:

public void ShowPosts([ARFetch(Eager = "Posts")] Blog blog) { ... }

It's useful when you know that you'll iterate through a lazy
collection in an specific action, and want to save the database
roundtrip without hacking your mappings.

Ayende,

Can you check the changes on r3723? Is that the best way to perform
eager fetching when loading an object?

I'm pasting the relevant code:

        // load using eager fetching of lazy collections
        DetachedCriteria criteria = DetachedCriteria.For(type);
        criteria.Add(Expression.Eq( pkModel.Property.Name, convertedPk));

        foreach (string associationToEagerFetch in attr.Eager.Split(','))
        {
                string clean = associationToEagerFetch.Trim();
                if ( clean.Length == 0)
Reply all
Reply to author
Forward
0 new messages