示例#1
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.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             using (SQLHelper ORMObject = new SQLHelper(Database.Name))
             {
                 if (Mapping.AllCommand == null)
                 {
                     ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.All <ObjectType>("*", 0, "", ReturnValues, () => Manager.Create <ObjectType>(), false, Parameters);
                 }
                 else
                 {
                     ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.All <ObjectType>(Mapping.AllCommand.SQLCommand, Mapping.AllCommand.CommandType, ReturnValues, () => Manager.Create <ObjectType>(), false, Parameters);
                 }
             }
         }
     }
     foreach (ObjectType ReturnValue in ReturnValues)
     {
         IORMObject TempReturn = ReturnValue as IORMObject;
         if (TempReturn != null)
         {
             TempReturn.Session0 = CurrentSession;
         }
     }
     return(ReturnValues);
 }
示例#2
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.Where(x => x.Readable).OrderBy(x => x.Order))
            {
                IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
                if (Mapping != null)
                {
                    using (SQLHelper ORMObject = new SQLHelper(Database.Name))
                    {
                        if (Mapping.AnyCommand == null)
                        {
                            ReturnValue = ORMObject.Any <ObjectType>("*", ReturnValue, () => Manager.Create <ObjectType>(), false, Parameters);
                        }
                        else
                        {
                            ReturnValue = ORMObject.Any <ObjectType>(Mapping.AnyCommand.SQLCommand, Mapping.AnyCommand.CommandType, ReturnValue, () => Manager.Create <ObjectType>(), false, Parameters);
                        }
                    }
                }
            }
            IORMObject TempReturnValue = ReturnValue as IORMObject;

            if (TempReturnValue != null)
            {
                TempReturnValue.Session0 = CurrentSession;
            }
            return(ReturnValue);
        }
示例#3
0
 public virtual System.Collections.Generic.List <DataType> LoadListProperties <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.Where(x => x.Readable).OrderBy(x => x.Order))
     {
         IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
         if (Mapping != null)
         {
             IProperty Property = Mapping.Properties.FirstOrDefault(x => x.Type == typeof(DataType) &&
                                                                    x.Name == PropertyName);
             if (Property != null)
             {
                 using (SQLHelper ORMObject = new SQLHelper(Database.Name))
                 {
                     if (Property.CommandToLoad == null)
                     {
                         ReturnValue = (System.Collections.Generic.List <DataType>)ORMObject.All <DataType>("*", 0, "", ReturnValue, () => Manager.Create <DataType>(), false, Parameters);
                     }
                     else
                     {
                         ReturnValue = (System.Collections.Generic.List <DataType>)ORMObject.All <DataType>(Property.CommandToLoad.SQLCommand, Property.CommandToLoad.CommandType, ReturnValue, () => Manager.Create <DataType>(), false, Parameters);
                     }
                 }
             }
         }
     }
     foreach (DataType Item in ReturnValue)
     {
         IORMObject TempItem = Item as IORMObject;
         if (TempItem != null)
         {
             TempItem.Session0 = CurrentSession;
         }
     }
     return(ReturnValue);
 }
示例#4
0
 /// <summary>
 /// Returns a paged list of items
 /// </summary>
 /// <typeparam name="ObjectType">Object type</typeparam>
 /// <param name="Columns">Columns to load</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> Paged <ObjectType>(Session CurrentSession, string Columns = "*", 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 (SQLHelper ORMObject = new SQLHelper(Database.Name))
             {
                 ReturnValues = (System.Collections.Generic.List <ObjectType>)ORMObject.Paged <ObjectType>(Columns, OrderBy, PageSize, CurrentPage, ReturnValues, () => Manager.Create <ObjectType>(), false, Parameters);
             }
         }
     }
     foreach (ObjectType ReturnValue in ReturnValues)
     {
         IORMObject TempReturn = ReturnValue as IORMObject;
         if (TempReturn != null)
         {
             TempReturn.Session0 = CurrentSession;
         }
     }
     return(ReturnValues);
 }
示例#5
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.Where(x => x.Readable).OrderBy(x => x.Order))
            {
                IMapping Mapping = Mappings[Database].FirstOrDefault(x => x.ObjectType == typeof(ObjectType));
                if (Mapping != null)
                {
                    IProperty Property = Mapping.Properties.FirstOrDefault(x => x.Type == typeof(DataType) && x.Name == PropertyName);
                    if (Property != null)
                    {
                        using (SQLHelper ORMObject = new SQLHelper(Database.Name))
                        {
                            if (Property.CommandToLoad == null)
                            {
                                ReturnValue = ORMObject.Any <DataType>("*", ReturnValue, () => Manager.Create <DataType>(), false, Parameters);
                            }
                            else
                            {
                                ReturnValue = ORMObject.Any <DataType>(Property.CommandToLoad.SQLCommand, Property.CommandToLoad.CommandType, ReturnValue, () => Manager.Create <DataType>(), false, Parameters);
                            }
                        }
                    }
                }
            }
            IORMObject TempReturn = ReturnValue as IORMObject;

            if (TempReturn != null)
            {
                TempReturn.Session0 = CurrentSession;
            }
            return(ReturnValue);
        }