Beispiel #1
0
        /// <summary>
        /// ctor takes an IHasId.  Kacks if it isn't.
        /// </summary>
        public StoredObjectId(IHasId iHasId)
        {
            Condition.Requires(iHasId).IsNotNull();

            //copy the id/type over
            this._objectId   = iHasId.Id;
            this._objectType = iHasId.GetType();
        }
Beispiel #2
0
        /// <summary>
        /// returns a search filter that finds other objects that have the same id but not the same type
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static LogicOfTo <IHasId, bool> GetFindSameIdDiffTypeSearchFilter(IHasId obj)
        {
            LogicOfTo <IHasId, bool> filter = LogicOfTo <IHasId, bool> .New((item) =>
            {
                bool hasSameId  = item.Id.Equals(obj.Id);
                bool isSameType = item.GetType().Equals(obj.GetType());
                return(hasSameId && (!isSameType));
            });

            return(filter);
        }
Beispiel #3
0
        /// <summary>
        /// returns a search filter that finds other objects that have the same id but not the same type
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static LogicOfTo<IHasId,bool> GetFindSameIdDiffTypeSearchFilter(IHasId obj)
        {
            LogicOfTo<IHasId, bool> filter = LogicOfTo<IHasId, bool>.New((item) =>
            {
                bool hasSameId = item.Id.Equals(obj.Id);
                bool isSameType = item.GetType().Equals(obj.GetType());
                return hasSameId && (!isSameType);
            });

            return filter;
        }
Beispiel #4
0
        private void ScanGraph(IHasId entity, HashSet <object> toAdd, HashSet <object> other)
        {
            if (!toAdd.Contains(entity) && !other.Contains(entity))
            {
                (entity.Id == 0 ? toAdd : other).Add(entity);

                ObjectContext objContext    = ((IObjectContextAdapter)_context).ObjectContext;
                Type          entityClrType = entity.GetType();
                EntityType    entityType    = objContext.MetadataWorkspace.GetItems <EntityType>(DataSpace.CSpace).Single(t => t.Name == entityClrType.Name);

                foreach (NavigationProperty prop in entityType.NavigationProperties)
                {
                    string propertyName = prop.Name;
                    Type   propertyType = entity.GetType().GetProperty(propertyName).PropertyType;
                    bool   isCollection = typeof(IEnumerable).IsAssignableFrom(propertyType);
                    if (isCollection)
                    {
                        IEnumerable collection = (IEnumerable)_context.Entry(entity).Collection(propertyName).CurrentValue;
                        if (collection != null)
                        {
                            foreach (var item in collection)
                            {
                                if (item != null)
                                {
                                    ScanGraph((IHasId)item, toAdd, other);
                                }
                            }
                        }
                    }
                    else
                    {
                        IHasId referenceEntity = (IHasId)_context.Entry(entity).Reference(propertyName).CurrentValue;
                        if (referenceEntity != null)
                        {
                            ScanGraph(referenceEntity, toAdd, other);
                        }
                    }
                }
            }
        }