Пример #1
0
        public override void JoinsDelete(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return;
            }
            IEnumerable <DataType> List = CompiledExpression(Object);

            if (List == null)
            {
                return;
            }
            foreach (DataType Item in List)
            {
                if (Item != null)
                {
                    IParameter CurrentIDParameter = ((IProperty <ClassType>)Mapping.IDProperty).GetAsParameter(Object);
                    CurrentIDParameter.ID = "ID";
                    MicroORM.Command      = "DELETE FROM " + TableName + " WHERE " + Mapping.TableName + Mapping.IDProperty.FieldName + "=@ID";
                    MicroORM.CommandType  = CommandType.Text;
                    CurrentIDParameter.AddParameter(MicroORM);
                    MicroORM.ExecuteNonQuery();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Loads a property
        /// </summary>
        /// <typeparam name="ObjectType">Object type</typeparam>
        /// <typeparam name="DataType">Property type</typeparam>
        /// <param name="CurrentSession">Current session</param>
        /// <param name="Object">Object</param>
        /// <param name="PropertyName">Property name</param>
        /// <param name="Parameters">Extra parameters</param>
        /// <returns>The appropriate property value</returns>
        public virtual DataType LoadProperty <ObjectType, DataType>(Session CurrentSession, ObjectType Object, string PropertyName, params IParameter[] Parameters)
            where ObjectType : class, new()
            where DataType : class, new()
        {
            DataType ReturnValue = null;

            foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
            {
                IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
                if (Mapping != null)
                {
                    IProperty Property = Mapping.Properties.First(x => x.Type == typeof(DataType) && x.Name == PropertyName);
                    if (Property != null)
                    {
                        using (MicroORM ORMObject = new MicroORM(Database.Name))
                        {
                            if (Property.CommandToLoad == null)
                            {
                                ReturnValue = ORMObject.Map <DataType>().Any("*", ReturnValue, () => Manager.Create <DataType>(), Parameters);
                            }
                            else
                            {
                                ReturnValue = ORMObject.Map <DataType>().Any(Property.CommandToLoad.CommandToRun, Property.CommandToLoad.CommandType, ReturnValue, () => Manager.Create <DataType>(), Parameters);
                            }
                        }
                    }
                }
            }
            if (ReturnValue is IORMObject)
            {
                ((IORMObject)ReturnValue).Session0 = CurrentSession;
            }
            return(ReturnValue);
        }
Пример #3
0
        public override void CascadeSave(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return;
            }
            IEnumerable <DataType> List = CompiledExpression(Object);

            if (List == null)
            {
                return;
            }
            foreach (DataType Item in List)
            {
                if (Item != null)
                {
                    foreach (IProperty Property in Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType).Properties)
                    {
                        if (Property.Cascade)
                        {
                            ((IProperty <DataType>)Property).CascadeSave(Item, MicroORM);
                        }
                    }
                    ((IProperty <DataType>)Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType).IDProperty).CascadeSave(Item, MicroORM);
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Returns a list of objects that meet the criteria
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="Parameters">Parameters used in the where clause</param>
 /// <returns>A list of objects that meet the criteria</returns>
 public virtual IEnumerable <ObjectType> All <ObjectType>(Session CurrentSession, params IParameter[] Parameters) where ObjectType : class, new()
 {
     System.Collections.Generic.List <ObjectType> ReturnValues = new System.Collections.Generic.List <ObjectType>();
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 if (Mapping.AllCommand == null)
                 {
                     ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.Map <ObjectType>().All("*", 0, "", ReturnValues, () => Manager.Create <ObjectType>(), Parameters);
                 }
                 else
                 {
                     ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.Map <ObjectType>().All(Mapping.AllCommand.CommandToRun, Mapping.AllCommand.CommandType, ReturnValues, () => Manager.Create <ObjectType>(), Parameters);
                 }
             }
         }
     }
     foreach (ObjectType ReturnValue in ReturnValues)
     {
         if (ReturnValue is IORMObject)
         {
             ((IORMObject)ReturnValue).Session0 = CurrentSession;
         }
     }
     return(ReturnValues);
 }
        public override IEnumerable <Command> JoinsDelete(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return(new List <Command>());
            }
            DataType List = CompiledExpression(Object);

            if (List == null)
            {
                return(new List <Command>());
            }
            List <Command> Commands           = new List <Command>();
            object         CurrentIDParameter = ((IProperty <ClassType>)Mapping.IDProperty).GetAsObject(Object);
            IMapping       ForeignMapping     = Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType);

            if (ForeignMapping == Mapping)
            {
                Commands.AddIfUnique(new Command("DELETE FROM " + TableName + " WHERE " + Mapping.TableName + Mapping.IDProperty.FieldName + "2=@0",
                                                 CommandType.Text,
                                                 CurrentIDParameter));
            }
            else
            {
                Commands.AddIfUnique(new Command("DELETE FROM " + TableName + " WHERE " + Mapping.TableName + Mapping.IDProperty.FieldName + "=@0",
                                                 CommandType.Text,
                                                 CurrentIDParameter));
            }
            return(Commands);
        }
Пример #6
0
 /// <summary>
 /// Returns any item that matches the criteria
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Parameters">Parameters used in the where clause</param>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="ReturnValue">Return value</param>
 /// <returns>First item matching the criteria</returns>
 public virtual ObjectType Any <ObjectType>(Session CurrentSession, ObjectType ReturnValue = null, params IParameter[] Parameters) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 if (Mapping.AnyCommand == null)
                 {
                     ReturnValue = ORMObject.Map <ObjectType>().Any("*", ReturnValue, () => Manager.Create <ObjectType>(), Parameters);
                 }
                 else
                 {
                     ReturnValue = ORMObject.Map <ObjectType>().Any(Mapping.AnyCommand.CommandToRun, Mapping.AnyCommand.CommandType, ReturnValue, () => Manager.Create <ObjectType>(), Parameters);
                 }
             }
         }
     }
     if (ReturnValue is IORMObject)
     {
         ((IORMObject)ReturnValue).Session0 = CurrentSession;
     }
     return(ReturnValue);
 }
        public override IEnumerable <Command> CascadeJoinsSave(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return(new List <Command>());
            }
            DataType Item = CompiledExpression(Object);

            if (Item == null)
            {
                return(new List <Command>());
            }
            List <Command> Commands = new List <Command>();

            foreach (IProperty Property in Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType).Properties)
            {
                if (!Property.Cascade &&
                    (Property is IManyToMany ||
                     Property is IManyToOne ||
                     Property is IIEnumerableManyToOne ||
                     Property is IListManyToMany ||
                     Property is IListManyToOne))
                {
                    Commands.AddIfUnique(((IProperty <DataType>)Property).JoinsSave(Item, MicroORM));
                }
                if (Property.Cascade)
                {
                    Commands.AddIfUnique(((IProperty <DataType>)Property).CascadeJoinsSave(Item, MicroORM));
                }
            }

            Commands.AddIfUnique(JoinsSave(Object, MicroORM));
            return(Commands);
        }
Пример #8
0
        public override void JoinsSave(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return;
            }
            IEnumerable <DataType> List = CompiledExpression(Object);

            if (List == null)
            {
                return;
            }
            foreach (DataType Item in List)
            {
                if (Item != null)
                {
                    IParameter CurrentIDParameter = ((IProperty <ClassType>)Mapping.IDProperty).GetAsParameter(Object);
                    IMapping   ForeignMapping     = Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType);
                    IParameter ForeignIDParameter = ((IProperty <DataType>)ForeignMapping.IDProperty).GetAsParameter(Item);
                    CurrentIDParameter.ID = "ID1";
                    ForeignIDParameter.ID = "ID2";
                    MicroORM.Command      = "INSERT INTO " + TableName + "(" + Mapping.TableName + Mapping.IDProperty.FieldName + "," + ForeignMapping.TableName + ForeignMapping.IDProperty.FieldName + ") VALUES (@ID1,@ID2)";
                    MicroORM.CommandType  = CommandType.Text;
                    CurrentIDParameter.AddParameter(MicroORM);
                    ForeignIDParameter.AddParameter(MicroORM);
                    MicroORM.ExecuteNonQuery();
                }
            }
        }
Пример #9
0
 public override void CascadeDelete(ClassType Object, MicroORM MicroORM)
 {
     if (Object == null)
     {
         return;
     }
     MicroORM.Map <ClassType>().Delete(Object);
 }
Пример #10
0
        public void AddToQueryProvider(IDatabase Database)
        {
            Mapping <ClassType> Map = MicroORM.Map <ClassType>(TableName, IDProperty.Chain(x => x.FieldName), IDProperty.Chain(x => x.AutoIncrement), Database.Chain(x => x.ParameterStarter), Database.Chain(x => x.Name));

            ((IProperty <ClassType>)IDProperty).Chain(x => x.AddToQueryProvider(Database, Map));
            foreach (IProperty Property in Properties)
            {
                ((IProperty <ClassType>)Property).AddToQueryProvider(Database, Map);
            }
        }
Пример #11
0
 /// <summary>
 /// Gets the number of pages based on the specified info
 /// </summary>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="PageSize">Page size</param>
 /// <param name="Parameters">Parameters to search by</param>
 /// <param name="Command">Command to get the page count of</param>
 /// <returns>The number of pages that the table contains for the specified page size</returns>
 public virtual int PageCount <ObjectType>(Session CurrentSession, string Command, int PageSize = 25, params IParameter[] Parameters) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 return(ORMObject.Map <ObjectType>().PageCount(Command, PageSize, Parameters));
             }
         }
     }
     return(0);
 }
Пример #12
0
        public override IEnumerable <Command> JoinsSave(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return(new List <Command>());
            }
            IEnumerable <DataType> List = CompiledExpression(Object);

            if (List == null)
            {
                return(new List <Command>());
            }
            List <Command> Commands = new List <Command>();

            foreach (DataType Item in List)
            {
                if (Item != null)
                {
                    object   CurrentIDParameter = ((IProperty <ClassType>)Mapping.IDProperty).GetAsObject(Object);
                    IMapping ForeignMapping     = Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType);
                    object   ForeignIDParameter = ((IProperty <DataType>)ForeignMapping.IDProperty).GetAsObject(Item);
                    string   Parameters         = "";
                    object[] Values             = new object[2];
                    if (ForeignMapping == Mapping)
                    {
                        Parameters = Mapping.TableName + Mapping.IDProperty.FieldName + "," + ForeignMapping.TableName + ForeignMapping.IDProperty.FieldName + "2";
                        Values[0]  = CurrentIDParameter;
                        Values[1]  = ForeignIDParameter;
                    }
                    else if (Mapping.TableName.CompareTo(ForeignMapping.TableName) <= 0)
                    {
                        Parameters = Mapping.TableName + Mapping.IDProperty.FieldName + "," + ForeignMapping.TableName + ForeignMapping.IDProperty.FieldName;
                        Values[0]  = CurrentIDParameter;
                        Values[1]  = ForeignIDParameter;
                    }
                    else
                    {
                        Parameters = ForeignMapping.TableName + ForeignMapping.IDProperty.FieldName + "," + Mapping.TableName + Mapping.IDProperty.FieldName;
                        Values[1]  = CurrentIDParameter;
                        Values[0]  = ForeignIDParameter;
                    }
                    Commands.AddIfUnique(new Command("INSERT INTO " + TableName + "(" + Parameters + ") VALUES (@0,@1)",
                                                     CommandType.Text,
                                                     Values));
                }
            }
            return(Commands);
        }
Пример #13
0
 /// <summary>
 /// Runs a scalar command using the specified aggregate function
 /// </summary>
 /// <typeparam name="DataType">Data type</typeparam>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="AggregateFunction">Aggregate function</param>
 /// <param name="Parameters">Parameters</param>
 /// <returns>The scalar value returned by the command</returns>
 public virtual DataType Scalar <ObjectType, DataType>(Session CurrentSession, string AggregateFunction, params IParameter[] Parameters)
     where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 return(ORMObject.Map <ObjectType>().Scalar <DataType>(AggregateFunction, Parameters));
             }
         }
     }
     return(default(DataType));
 }
Пример #14
0
        public override void CascadeSave(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return;
            }
            List <IParameter> Params = new List <IParameter>();

            foreach (IProperty Property in Mapping.Properties)
            {
                IParameter Parameter = ((IProperty <ClassType>)Property).GetAsParameter(Object);
                if (Parameter != null)
                {
                    Params.Add(Parameter);
                }
            }
            MicroORM.Map <ClassType>().Save <DataType>(Object, Params.ToArray());
        }
Пример #15
0
 /// <summary>
 /// Returns any item that matches the criteria
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Command">Command to run</param>
 /// <param name="CommandType">Command type</param>
 /// <param name="Parameters">Parameters used in the where clause</param>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="ReturnValue">Return value</param>
 /// <returns>First item that matches the criteria</returns>
 public virtual ObjectType Any <ObjectType>(Session CurrentSession, string Command, CommandType CommandType, ObjectType ReturnValue = null, params IParameter[] Parameters) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         if (Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType)) != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 ReturnValue = ORMObject.Map <ObjectType>().Any(Command, CommandType, ReturnValue, () => Manager.Create <ObjectType>(), Parameters);
             }
         }
     }
     if (ReturnValue is IORMObject)
     {
         ((IORMObject)ReturnValue).Session0 = CurrentSession;
     }
     return(ReturnValue);
 }
Пример #16
0
 /// <summary>
 /// Saves an object to the database
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <typeparam name="PrimaryKeyType">Primary key type</typeparam>
 /// <param name="Object">Object to save</param>
 /// <param name="Parameters">Extra parameters used in saving the object</param>
 public virtual void Save <ObjectType, PrimaryKeyType>(ObjectType Object, params IParameter[] Parameters) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     if (Property.Cascade)
                     {
                         ((IProperty <ObjectType>)Property).CascadeSave(Object, ORMObject);
                     }
                 }
                 System.Collections.Generic.List <IParameter> Params = Parameters.ToList();
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     IParameter Parameter = ((IProperty <ObjectType>)Property).GetAsParameter(Object);
                     if (Parameter != null)
                     {
                         Params.Add(Parameter);
                     }
                 }
                 ORMObject.Map <ObjectType>().Save <PrimaryKeyType>(Object, Params.ToArray());
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     if (!Property.Cascade && (Property is IManyToMany || Property is IManyToOne || Property is IIEnumerableManyToOne))
                     {
                         ((IProperty <ObjectType>)Property).JoinsDelete(Object, ORMObject);
                         ((IProperty <ObjectType>)Property).JoinsSave(Object, ORMObject);
                     }
                     if (Property.Cascade)
                     {
                         ((IProperty <ObjectType>)Property).CascadeJoinsDelete(Object, ORMObject);
                         ((IProperty <ObjectType>)Property).CascadeJoinsSave(Object, ORMObject);
                     }
                 }
             }
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Sets up the system
        /// </summary>
        /// <param name="AssemblyUsing">Assembly to set up</param>
        private void Setup(Assembly AssemblyUsing)
        {
            if (Databases == null)
            {
                Databases = new System.Collections.Generic.List <IDatabase>();
            }
            IEnumerable <Type> Types = AssemblyUsing.GetTypes(typeof(IDatabase));

            foreach (Type Type in Types)
            {
                Type      BaseType   = Type.BaseType;
                IDatabase TempObject = (IDatabase)Activator.CreateInstance(Type);
                if (!string.IsNullOrEmpty(TempObject.ConnectionString))
                {
                    MicroORM.Database(TempObject.ConnectionString, TempObject.Name);
                    Databases.Add(TempObject);
                }
            }
            Manager = new Reflection.AOP.AOPManager();
        }
Пример #18
0
        public override IEnumerable <Command> JoinsDelete(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return(new List <Command>());
            }
            IEnumerable <DataType> List = CompiledExpression(Object);

            if (List == null)
            {
                return(new List <Command>());
            }
            List <Command> Commands           = new List <Command>();
            object         CurrentIDParameter = ((IProperty <ClassType>)Mapping.IDProperty).GetAsObject(Object);

            Commands.AddIfUnique(new Command("DELETE FROM " + TableName + " WHERE " + Mapping.TableName + Mapping.IDProperty.FieldName + "=@0",
                                             CommandType.Text,
                                             CurrentIDParameter));
            return(Commands);
        }
Пример #19
0
        public override void CascadeJoinsDelete(ClassType Object, MicroORM MicroORM)
        {
            if (Object == null)
            {
                return;
            }
            DataType Item = CompiledExpression(Object);

            if (Item == null)
            {
                return;
            }
            foreach (IProperty Property in Mapping.Manager.Mappings[typeof(DataType)].First(x => x.DatabaseConfigType == Mapping.DatabaseConfigType).Properties)
            {
                if (Property.Cascade)
                {
                    ((IProperty <DataType>)Property).CascadeJoinsDelete(Item, MicroORM);
                }
            }
        }
Пример #20
0
 /// <summary>
 /// Deletes the specified object from the database
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Object">Object to delete</param>
 public virtual void Delete <ObjectType>(ObjectType Object) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     if (Property.Cascade)
                     {
                         ((IProperty <ObjectType>)Property).CascadeDelete(Object, ORMObject);
                     }
                 }
                 ORMObject.Map <ObjectType>().Delete(Object);
             }
         }
     }
 }
Пример #21
0
 /// <summary>
 /// Returns a list of objects that meet the criteria
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="CurrentSession">Current session</param>
 /// <param name="Columns">Columns to load</param>
 /// <param name="Limit">Limit on the number of items to return</param>
 /// <param name="OrderBy">Order by clause (minus the ORDER BY)</param>
 /// <param name="Parameters">Parameters used in the where clause</param>
 /// <returns>A list of objects that meet the criteria</returns>
 public virtual IEnumerable <ObjectType> All <ObjectType>(Session CurrentSession, string Columns, int Limit, string OrderBy, params IParameter[] Parameters) where ObjectType : class, new()
 {
     System.Collections.Generic.List <ObjectType> ReturnValues = new System.Collections.Generic.List <ObjectType>();
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         if (Mappings[Database].First(x => x.ObjectType == typeof(ObjectType)) != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.Map <ObjectType>().All(Columns, Limit, OrderBy, ReturnValues, () => Manager.Create <ObjectType>(), Parameters);
             }
         }
     }
     foreach (ObjectType ReturnValue in ReturnValues)
     {
         if (ReturnValue is IORMObject)
         {
             ((IORMObject)ReturnValue).Session0 = CurrentSession;
         }
     }
     return(ReturnValues);
 }
Пример #22
0
 /// <summary>
 /// Deletes the specified object from the database
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Object">Object to delete</param>
 public virtual void Delete <ObjectType>(ObjectType Object) where ObjectType : class, new()
 {
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Writable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 System.Collections.Generic.List <Command> JoinCommands = new System.Collections.Generic.List <Command>();
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     if (!Property.Cascade && Mapping.ObjectType == Property.Type)
                     {
                         JoinCommands.AddIfUnique(((IProperty <ObjectType>)Property).JoinsDelete(Object, ORMObject));
                     }
                     if (Property.Cascade)
                     {
                         JoinCommands.AddIfUnique(((IProperty <ObjectType>)Property).CascadeJoinsDelete(Object, ORMObject));
                     }
                 }
                 foreach (Command JoinCommand in JoinCommands)
                 {
                     ORMObject.ChangeCommand(JoinCommand);
                     ORMObject.ExecuteNonQuery();
                 }
                 foreach (IProperty Property in Mapping.Properties)
                 {
                     if (Property.Cascade)
                     {
                         ((IProperty <ObjectType>)Property).CascadeDelete(Object, ORMObject);
                     }
                 }
                 ORMObject.Map <ObjectType>().Delete(Object);
             }
         }
     }
 }
Пример #23
0
 /// <summary>
 /// Returns a paged list of items
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Command">Command to use</param>
 /// <param name="OrderBy">Order by clause (minus the ORDER BY part)</param>
 /// <param name="PageSize">Page size</param>
 /// <param name="CurrentPage">Current page (starting with 0)</param>
 /// <param name="Parameters">Parameters used in the where clause</param>
 /// <param name="CurrentSession">Current session to use in the query</param>
 /// <returns>A paged list of items that match the criteria</returns>
 public virtual IEnumerable <ObjectType> PagedCommand <ObjectType>(Session CurrentSession, string Command, string OrderBy = "", int PageSize = 25, int CurrentPage = 0, params IParameter[] Parameters) where ObjectType : class, new()
 {
     System.Collections.Generic.List <ObjectType> ReturnValues = new System.Collections.Generic.List <ObjectType>();
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (MicroORM ORMObject = new MicroORM(Database.Name))
             {
                 ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.Map <ObjectType>().PagedCommand(Command, OrderBy, PageSize, CurrentPage, ReturnValues, () => Manager.Create <ObjectType>(), Parameters);
             }
         }
     }
     foreach (ObjectType ReturnValue in ReturnValues)
     {
         if (ReturnValue is IORMObject)
         {
             ((IORMObject)ReturnValue).Session0 = CurrentSession;
         }
     }
     return(ReturnValues);
 }
Пример #24
0
 /// <summary>
 /// Loads a property
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <typeparam name="DataType">Property type</typeparam>
 /// <param name="CurrentSession">Current Session</param>
 /// <param name="Object">Object</param>
 /// <param name="PropertyName">Property name</param>
 /// <param name="Parameters">Extra parameters</param>
 /// <returns>The appropriate property value</returns>
 public virtual IEnumerable <DataType> LoadProperties <ObjectType, DataType>(Session CurrentSession, ObjectType Object, string PropertyName, params IParameter[] Parameters)
     where ObjectType : class, new()
     where DataType : class, new()
 {
     System.Collections.Generic.List <DataType> ReturnValue = new System.Collections.Generic.List <DataType>();
     foreach (IDatabase Database in Mappings.Keys.OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].First(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             IProperty Property = Mapping.Properties.First(x => x.Type == typeof(DataType) &&
                                                           x.Name == PropertyName);
             if (Property != null)
             {
                 using (MicroORM ORMObject = new MicroORM(Database.Name))
                 {
                     if (Property.CommandToLoad == null)
                     {
                         ReturnValue = (System.Collections.Generic.List <DataType>)ORMObject.Map <DataType>().All("*", 0, "", ReturnValue, () => Manager.Create <DataType>(), Parameters);
                     }
                     else
                     {
                         ReturnValue = (System.Collections.Generic.List <DataType>)ORMObject.Map <DataType>().All(Property.CommandToLoad.CommandToRun, Property.CommandToLoad.CommandType, ReturnValue, () => Manager.Create <DataType>(), Parameters);
                     }
                 }
             }
         }
     }
     foreach (DataType Item in ReturnValue)
     {
         if (Item is IORMObject)
         {
             ((IORMObject)Item).Session0 = CurrentSession;
         }
     }
     return(ReturnValue);
 }
Пример #25
0
        public override void CascadeSave(ClassType Object, MicroORM MicroORM)
        {

        }
Пример #26
0
 public override IEnumerable<Command> CascadeJoinsSave(ClassType Object, MicroORM MicroORM)
 {
     return new List<Command>();
 }
Пример #27
0
 public override IEnumerable<Command> JoinsDelete(ClassType Object, MicroORM MicroORM)
 {
     return new List<Command>();
 }
Пример #28
0
 public override void CascadeJoinsDelete(ClassType Object, MicroORM MicroORM)
 {
 }
Пример #29
0
 public override void JoinsSave(ClassType Object, MicroORM MicroORM)
 {
 }
Пример #30
0
 /// <summary>
 /// Join save
 /// </summary>
 /// <param name="Object">Object</param>
 /// <param name="MicroORM">ORM object</param>
 /// <returns>List of commands</returns>
 public abstract IEnumerable <Command> JoinsSave(ClassType Object, MicroORM MicroORM);