public static void SetEntityKey(this IRelatedEnd relatedEnd, EntityKey key) { Debug.Assert(relatedEnd.IsEntityReference()); Type relationshipType = relatedEnd.GetType(); PropertyInfo pi = relationshipType.GetProperty("EntityKey"); pi.SetValue(relatedEnd, key, null); }
public static EntityKey GetEntityKey(this IRelatedEnd relatedEnd) { Debug.Assert(relatedEnd.IsEntityReference()); Type relationshipType = relatedEnd.GetType(); PropertyInfo pi = relationshipType.GetProperty("EntityKey"); return((EntityKey)pi.GetValue(relatedEnd, null)); }
private static IEnumerable <TEntity> ExtractSingle <TEntity>(IRelatedEnd relatedEnd) where TEntity : class { var valueProp = relatedEnd.GetType().GetProperty("Value"); var value = valueProp?.GetValue(relatedEnd); yield return(value as TEntity); }
private void AttachRelationManyEntity(FBEntity entity, IRelatedEnd re) { Type t = re.GetType(); Type eType = t.GetGenericArguments()[0]; if (!re.IsLoaded) { re.Load(); } RelationManyEntity rManyE = new RelationManyEntity(); rManyE.EntityType = eType.Name; rManyE.RelationshipName = re.RelationshipName; rManyE.PropertyName = re.TargetRoleName; entity.CollectionEntity.Add(rManyE); foreach (var item in re) { FBEntity tempEntity = new FBEntity(); tempEntity.Entity = item as EntityObject; rManyE.FBEntities.Add(tempEntity); } //rManyE.FBEntities.ForEach(item => // { // try // { // IEntityWithRelationships ie = item.Entity as IEntityWithRelationships; // re.Remove(ie); // } // catch (Exception ex) // { // } // }); }
// // IRelatedEnd methods // public static bool IsEntityReference(this IRelatedEnd relatedEnd) { Type relationshipType = relatedEnd.GetType(); return(relationshipType.GetGenericTypeDefinition() == typeof(EntityReference <>)); }
private void AttachRelationManyEntity(FBEntity entity, IRelatedEnd re) { Type t = re.GetType(); Type eType = t.GetGenericArguments()[0]; if (!re.IsLoaded) re.Load(); RelationManyEntity rManyE = new RelationManyEntity(); rManyE.EntityType = eType.Name; rManyE.RelationshipName = re.RelationshipName; rManyE.PropertyName = re.TargetRoleName; entity.CollectionEntity.Add(rManyE); foreach (var item in re) { FBEntity tempEntity = new FBEntity(); tempEntity.Entity = item as EntityObject; rManyE.FBEntities.Add(tempEntity); } //rManyE.FBEntities.ForEach(item => // { // try // { // IEntityWithRelationships ie = item.Entity as IEntityWithRelationships; // re.Remove(ie); // } // catch (Exception ex) // { // } // }); }