using System; using System.Linq; using System.Linq.Expressions; using Marr.Data; using Marr.Data.Mapping; namespace NzbDrone.Core.Datastore { public static class RelationshipExtensions { public static RelationshipBuilder HasOne(this ColumnMapBuilder columnMapBuilder, Expression> portalExpression, Func childIdSelector) where TParent : ModelBase where TChild : ModelBase { return columnMapBuilder.Relationships.AutoMapComplexTypeProperties() .For(portalExpression) .LazyLoad((db, parent) => db.Query().Single(c => c.Id == childIdSelector(parent))); } public static RelationshipBuilder HasMany(this ColumnMapBuilder columnMapBuilder, Expression> portalExpression, Func childIdSelector) where TParent : ModelBase where TChild : ModelBase { return columnMapBuilder.Relationships.AutoMapComplexTypeProperties() .For(portalExpression) .LazyLoad((db, parent) => db.Query().Where(c => c.Id == childIdSelector(parent)).ToList()); } } }