|
|
@ -70,14 +70,15 @@ namespace Marr.Data
|
|
|
|
internal class LazyLoaded<TParent, TChild> : LazyLoaded<TChild>
|
|
|
|
internal class LazyLoaded<TParent, TChild> : LazyLoaded<TChild>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private TParent _parent;
|
|
|
|
private TParent _parent;
|
|
|
|
private Func<IDataMapper, TParent, TChild> _query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Func<IDataMapper> _dbCreator;
|
|
|
|
private Func<IDataMapper> _dbCreator;
|
|
|
|
|
|
|
|
|
|
|
|
internal LazyLoaded(Func<IDataMapper, TParent, TChild> query)
|
|
|
|
private readonly Func<IDataMapper, TParent, TChild> _query;
|
|
|
|
: base()
|
|
|
|
private readonly Func<TParent, bool> _condition;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal LazyLoaded(Func<IDataMapper, TParent, TChild> query, Func<TParent, bool> condition = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_query = query;
|
|
|
|
_query = query;
|
|
|
|
|
|
|
|
_condition = condition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LazyLoaded(TChild val)
|
|
|
|
public LazyLoaded(TChild val)
|
|
|
@ -106,13 +107,18 @@ namespace Marr.Data
|
|
|
|
public override void LazyLoad()
|
|
|
|
public override void LazyLoad()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_isLoaded)
|
|
|
|
if (!_isLoaded)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_condition != null && _condition(_parent))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (IDataMapper db = _dbCreator())
|
|
|
|
using (IDataMapper db = _dbCreator())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_child = _query(db, _parent);
|
|
|
|
_child = _query(db, _parent);
|
|
|
|
_isLoaded = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_child = default(TChild);
|
|
|
|
|
|
|
|
_isLoaded = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator LazyLoaded<TParent, TChild>(TChild val)
|
|
|
|
public static implicit operator LazyLoaded<TParent, TChild>(TChild val)
|
|
|
|