Pregunta

I know I can do something like:

[BelongsTo("Foo", NotNull = true, Lazy = FetchWhen.Immediate)]
public Foo MyProperty
{

}

And this field will be populated immediately through a join rather than when the getter is accessed.

However, is it possible to specify whether the fetch is done immediately when I run the query, such as here:

MyModel[] foo = MyModel.FindAllByProperty("User", someUser);
//Sometimes I want lazy, sometimes I don't..

The .NET Entity Framework can do this using Include, such as:

var foos = from f in context.FOO.Include("Bar") where f.id == 123 select f;

And I believe Rails has this same feature using the :include syntax. I'm wondering if Castle ActiveRecord has an equivalent, or if laziness is always defined at the model level. Thanks!!

¿Fue útil?

Solución

Yes, it can. The recommended way is using lazy mappings by default, then eagerly fetch what you need for each case.

Defining eager fetches per query depends on the query API. For example, HQL uses the 'join fetch' keyword, with Criteria API you use SetFetchMode, etc.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top