Example #1
0
        /// <summary>
        /// Fetches all the entities of the specified type with the filter and fetches all the relationship
        /// properties of all the returned elements.
        /// </summary>
        /// <returns>List of all the elements of the type T that matches the filter with the children already loaded</returns>
        /// <param name="conn">SQLite Net connection object</param>
        /// <param name="filter">Filter that will be passed to the <c>Where</c> clause when fetching
        /// objects from the database. No relationship properties are allowed in this filter as they
        /// are loaded afterwards</param>
        /// <param name="recursive">If set to <c>true</c> all the relationships with
        /// <c>CascadeOperation.CascadeRead</c> will be loaded recusively.</param>
        /// <typeparam name="T">Entity type where the object should be fetched from</typeparam>
        public static List <T> GetAllWithChildren <T>(this SQLiteConnection conn, Expression <Func <T, bool> > filter = null, bool recursive = false) where T : new()
        {
            var elements = conn.Table <T>();

            if (filter != null)
            {
                elements = elements.Where(filter);
            }

            var list = elements.ToList();

            foreach (T element in list)
            {
                conn.GetChildren(element, recursive);
            }

            return(list);
        }