Lazy load column

In DbEntry, we can define a column as lazy load just by define a attribute on it:

public class User : DbObjectModel<User>
{
    public string Name { get; set; }
    [LazyLoad] public string Profile { get; set; }
}

When we read the object from database, only other columns will be read:

User u = User.FindById(1);

It will call SQL as:

Select [Id],[Name] From [User] Where [Id]=1

When we first use this column, it will read from database:

Console.Write(o.Profile);

It will call SQL as:

Select [Profile] From [User] Where [Id]=1

For some case we want to load the lazy load field(s) without lazy-load :( , to do so, use SelectNoLazy as following:

var list = User.Where(p => p.Id == 1).SelectNoLazy();

It will call SQL as:

Select [Id],[Name],[Profile] From [User] Where [Id]=1

So if we have some large columns and want to delay to load them, we can use this feature now.

Last edited Apr 9, 2014 at 1:58 PM by lifeng, version 8

Comments

No comments yet.