Ejemplo n.º 1
0
 private Type GetParentType(EFBase parent)
 {
   // parent might be inside a dynamic proxy assembly; need to convert
   return typeof(EFBase).Assembly.GetType($"{typeof(EFBase).Namespace}.{parent.GetType().Name.StripEnd()}");
 }
Ejemplo n.º 2
0
 public static List<EFBase> GetForeignKeyList(EFBase ancestor, PropertyInfo fkPropertyInfo)
 {
   IEnumerable col = null;
   string collectionPropertyName = fkPropertyInfo.Pluralize();
   foreach (var pi in GetPrimaryKeys(ancestor.GetType()).Where(pi => pi.Name != "Id").Reverse())
   {
     string ancestorPropertyName = pi.Name.StripEnd();
     ancestor = ancestor.LoadReference(ancestorPropertyName);
     var colPropertyInfo = ancestor.GetType().GetProperty(collectionPropertyName);
     if (colPropertyInfo != null)
     {
       col = (IEnumerable)colPropertyInfo.GetValue(ancestor);
       if (col == null)
         col = ancestor.LoadCollection(collectionPropertyName);
       break;
     }
   }
   return col.Cast<EFBase>().ToList();
 }
Ejemplo n.º 3
0
 private EFBase GetParent()
 {
   EFBase parent = null;
   if (Collection != null)
   {
     var fi = collection.GetType().GetField("Parent");
     if (fi != null)
       parent = (EFBase)fi.GetValue(collection);
   }
   if (parent == null)
   {
     if (ParentType != null && ParentKeys.Any())
     {
       var parentCollection = (IEnumerable)ParentType.GetProperty("Collection", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null, null);
       parent = (EFBase)parentCollection.GetType().GetMethod("Item").Invoke(parentCollection, new object[] { ParentKeys["Id"] });
     }
   }
   return parent;
 }