3

I have some questions about about lazy loading

When I have mapped my objects, I write .Not.LazyLoad() everywhere in my application and it works good. But I have some problems.
Example: I have a class User. It has properties Name and Comments. Mapping Comments in User:

HasMany(x => x.Comments).KeyColumn("UserId").Not.LazyLoad();

Which works good, but everywhere I load User, Comments get loaded with it, which is bad... Example of load User:

var user = session.Get<User>(1);

If the user has a lot of comments my application works bad...
The question is how do I enable LazyLoad if needed? Or how do I disable Lazy loading, if I don't write .Not.LazyLoad()?

4

1 に答える 1

4

私は私の質問の答えを見つけました。
どこにも書いておらず.Not.LazyLoad()、取得する必要がある場合はComments、次のように記述する必要があります (id=1 のユーザーを取得):

var user = session.QueryOver<User>()
                  .Fetch(u => u.Comments)
                  .Eager
                  .List()
                  .Where(u => u.Id == userId)
                  .FirstOrDefault();

または、何が必要ですか。

于 2012-05-28T13:15:19.700 に答える