public static Lazy <T> GenerateLazyChildCollectionMember <T>(ChildCollectionMember cm, object instance) where T : class, new() { var parentReferencedValue = cm.ParentReferencedProperty.GetValue(instance); var referencedColumnName = cm.ReferencedColumnName; Func <T> func = () => { dynamic queryParams = new System.Dynamic.ExpandoObject(); ((IDictionary <String, object>)queryParams).Add(referencedColumnName, parentReferencedValue); var mi = typeof(Model).GetMethod("_runLazyChildCollectionQuery", BindingFlags.NonPublic | BindingFlags.Static); var genericMi = mi.MakeGenericMethod(cm.CollectionType); return(genericMi.Invoke(null, new Object[] { queryParams }) as T); }; return(new Lazy <T>(func)); }
string _childCollectionParentColumnName(ChildCollectionMember ccm) { var lineage = new List <Member>(); Member member = ccm.ParentReferencedMember; if (member != null) { lineage.Add(member); while (member.Parent != null && !(member.Parent is ChildCollectionMember)) { lineage.Add(member.Parent); member = member.Parent; } } lineage.Reverse(); return(String.Join(".", lineage.Select(c => c.Name))); }