Exemplo n.º 1
0
        /// <summary>
        /// Does a cascade delete of an object for this property
        /// </summary>
        /// <param name="Object">Object</param>
        /// <param name="Source">Source info</param>
        /// <param name="ObjectsSeen">Objects seen thus far</param>
        /// <returns>Batch object with the appropriate commands</returns>
        public override IBatch CascadeDelete(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen)
        {
            QueryProvider.Manager Provider        = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>();
            Mapper.Manager        MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>();
            IMapping PropertyMapping = MappingProvider[typeof(DataType), Source];
            IBatch   Batch           = Provider.Batch(Source);
            var      AspectObject    = Object as IORMObject;

            if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object))))
            {
                return(Batch);
            }
            if (AspectObject != null)
            {
                ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object));
            }
            IEnumerable <DataType> IList = CompiledExpression(Object);

            if (IList == null)
            {
                return(Batch);
            }
            foreach (DataType Item in IList.Where(x => x != null))
            {
                foreach (IProperty <DataType> Property in PropertyMapping.Properties.Where(x => x.Cascade))
                {
                    Batch.AddCommand(Property.CascadeDelete(Item, Source, ObjectsSeen.ToList()));
                }
                Batch.AddCommand(Provider.Generate <DataType>(Source, PropertyMapping, Structure).Delete(Item));
            }
            Utilities.IoC.Manager.Bootstrapper.Resolve <DataTypes.Caching.Manager>().Cache().RemoveByTag(typeof(DataType).GetName());
            return(Batch);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Does a cascade save of an object for this property
 /// </summary>
 /// <param name="Object">Object</param>
 /// <param name="Source">Source info</param>
 /// <param name="ObjectsSeen">Objects that have been seen thus far</param>
 /// <returns>Batch object with the appropriate commands</returns>
 public override IBatch CascadeSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen)
 {
     QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>();
     if (Object == null || ObjectsSeen.Contains(GetValue(Object)))
     {
         return(Provider.Batch(Source));
     }
     return(Provider.Generate <ClassType>(Source, Mapping).Save <DataType>(Object));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Called to create a batch that saves items from the joining table
        /// </summary>
        /// <param name="Object">Object</param>
        /// <param name="Source">Source info</param>
        /// <param name="ObjectsSeen">Objects seen thus far</param>
        /// <returns>Batch object with the appropriate commands</returns>
        public override IBatch JoinsSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen)
        {
            QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>();
            var AspectObject = Object as IORMObject;

            if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object))))
            {
                return(Provider.Batch(Source));
            }
            if (AspectObject != null)
            {
                ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object));
            }
            return(Provider.Generate <ClassType>(Source, Mapping, Structure).JoinsSave <ICollection <DataType>, DataType>(this, Object));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called to create a batch that saves items from the joining tables
        /// </summary>
        /// <param name="Object">Object</param>
        /// <param name="Source">Source info</param>
        /// <param name="ObjectsSeen">Objects seen thus far</param>
        /// <returns>Batch object with the appropriate commands</returns>
        public override IBatch CascadeJoinsSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen)
        {
            QueryProvider.Manager Provider        = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>();
            Mapper.Manager        MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>();
            IMapping PropertyMapping = MappingProvider[typeof(DataType), Source];
            IBatch   Batch           = Provider.Batch(Source);
            var      AspectObject    = Object as IORMObject;

            if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object))))
            {
                return(Batch);
            }
            if (AspectObject != null)
            {
                ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object));
            }
            IEnumerable <DataType> IList = CompiledExpression(Object);

            if (IList == null)
            {
                return(Batch);
            }
            foreach (DataType Item in IList.Where(x => x != null))
            {
                foreach (IProperty <DataType> Property in PropertyMapping.Properties)
                {
                    if (!Property.Cascade &&
                        (Property is IMultiMapping ||
                         Property is ISingleMapping))
                    {
                        Batch.AddCommand(Property.JoinsSave(Item, Source, ObjectsSeen.ToList()));
                    }
                    else if (Property.Cascade)
                    {
                        Batch.AddCommand(Property.CascadeJoinsSave(Item, Source, ObjectsSeen.ToList()));
                    }
                }
            }
            Batch.AddCommand(Provider.Generate <ClassType>(Source, Mapping, Structure).JoinsSave <ICollection <DataType>, DataType>(this, Object));
            return(Batch);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Sets up the property
 /// </summary>
 /// <param name="MappingProvider">Mapping provider</param>
 /// <param name="QueryProvider">Query provider</param>
 /// <param name="Source">Source info</param>
 public override void Setup(ISourceInfo Source, Mapper.Manager MappingProvider, QueryProvider.Manager QueryProvider)
 {
     ForeignMapping = MappingProvider[Type, Source];
     Structure      = MappingProvider.GetStructure(Mapping.DatabaseConfigType);
     QueryProvider.Generate <ClassType>(Source, Mapping, Structure).SetupLoadCommands(this);
 }
 /// <summary>
 /// Sets up the property
 /// </summary>
 /// <param name="MappingProvider">Mapping provider</param>
 /// <param name="QueryProvider">Query provider</param>
 /// <param name="Source">Source info</param>
 public override void Setup(ISourceInfo Source, Mapper.Manager MappingProvider, QueryProvider.Manager QueryProvider)
 {
     ForeignMapping = MappingProvider[Type, Source];
     QueryProvider.Generate <ClassType>(Source, Mapping).SetupLoadCommands(this);
 }