Beispiel #1
0
        private void UpdateNode(Node nodeToUpdate, object entity)
        {
            string propVal = string.Empty;

            entity.GetType().GetProperties().Where(pr => pr.CanRead && MapperHelper.IsAnId(pr) == false).ToList().ForEach(property =>
            {
                if (MapperHelper.IsPrimitive(property.PropertyType))
                {
                    propVal = property.GetValue(entity, null).ToString();
                    if (nodeToUpdate.GetProperty(property.Name) != propVal)
                    {
                        nodeToUpdate.SetProperty(property.Name, propVal);
                    }
                }
            });
        }
Beispiel #2
0
        private static T Get <T>(Node node) where T : class
        {
            T entity = LazyLoader.EnableLazyLoading <T>();

            //if (node.GetProperty("clazz") != typeof(T).ToString())
            if (_reflectionHelper.CanCast(node.GetProperty("clazz"), typeof(T).ToString()) == false)
            {
                throw new InvalidCastException(string.Format("Retrieved object with ID '{0}' is an instance of '{1}' and unable to cast it to '{2}'", node.Id.ToString(), node.GetProperty("clazz"), typeof(T).ToString()));
            }
            typeof(T).GetProperties().Where(pr => pr.CanRead && MapperHelper.IsAnId(pr) == false).ToList().ForEach(property =>
            {
                property.SetValue(entity, MapperHelper.CastPropertyValue(property, node.GetProperty(property.Name)), null);
            });

            entity = MapperHelper.SetIdentity <T>(entity, node.Id);
            return(entity);
        }
Beispiel #3
0
        private object DoLazyLoad(Type type, object entity, string propertyName)
        {
            var        castedEntity = entity as IProxyTargetAccessor;
            Type       genericType  = type.IsGenericType ? type.GetGenericArguments()[0] : type;
            MethodInfo method       = typeof(NodeMapper).GetMethod("LoadRelatedEntitiesWithId");
            MethodInfo generic      = method.MakeGenericMethod(genericType);
            int        id           = MapperHelper.GetIdentity(castedEntity.DynProxyGetTarget());

            object result = generic.Invoke(null, new object[] { id, propertyName });

            if (type.Namespace != "System.Collections.Generic")
            {
                result = ((IEnumerable)result).Cast <object>().ToArray().FirstOrDefault();
            }

            return(result);
        }
Beispiel #4
0
        internal Node SaveAndReturnAsNode(object entity)
        {
            if (entity == null)
            {
                return(null);
            }
            int  id   = MapperHelper.GetIdentity(entity);
            Node node = null;

            if (id <= 0)
            {
                node = this.CreateNode(entity);
                node.Create();
                MapperHelper.SetIdentity(entity, node.Id);
            }
            else
            {
                node = Node.Get(id);
                this.UpdateNode(node, entity);
            }
            return(node);
        }
Beispiel #5
0
        public void Delete <T>(T entity) where T : class
        {
            Node node = Node.Get(MapperHelper.GetIdentity <T>(entity));

            node.Delete();
        }