Example #1
0
 public static List <T> GetAllFromEntity <T>() where T : class
 {
     using (var db = new TravianBotDB())
     {
         return(db.GetTable <T>().ToList());
     }
 }
Example #2
0
        //public static List<T> GetEntitiesByParameters<T>(Func<T, bool> where) where T : class
        //{
        //    using (var db = new TravianBotDB())
        //    {
        //        return db.GetTable<T>().Where<T>(where).Where<T>(GetLogicExclusion<T>()).ToList);
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">linqToDb Table mapped</typeparam>
        /// <param name="pk"> Have to be of the same type of primary key atribute of T table mapped</param>
        /// <returns>T linqToDb mapped class</returns>
        public static T GetEntityByPK <T>(object pk) where T : class
        {
            using (var db = new TravianBotDB())
            {
                var pkName     = typeof(T).GetProperties().Where(prop => prop.GetCustomAttributes(typeof(LinqToDB.Mapping.PrimaryKeyAttribute), false).Count() > 0).First();
                var expression = SimpleComparison <T>(pkName.Name, pk);

                return(db.GetTable <T>().Where <T>(expression).FirstOrDefault());
            }
        }
Example #3
0
        /// <summary>
        /// Excelent to use to get entities by FK
        /// </summary>
        /// <typeparam name="T">Entity To Filter From DB Mapped</typeparam>
        /// <typeparam name="D">Type of property to filter using Equals Comparer</typeparam>
        /// <param name="propertyName">Name of property</param>
        /// <param name="valueToFilter">Value to filter query</param>
        /// <returns>List of T</returns>
        public static List <T> GetAllEntititiesByPropertyValue <T, D>(string propertyName, D valueToFilter)
            where T : class
        {
            if (string.IsNullOrWhiteSpace(propertyName))
            {
                return(GetAllFromEntity <T>());
            }

            var expression = SimpleComparison <T, D>(propertyName, valueToFilter);

            using (var db = new TravianBotDB())
            {
                var data = db.GetTable <T>().Where <T>(expression).ToList();
                return(data);
            }
        }