public static List <T> GetAllFromEntity <T>() where T : class
 {
     using (var db = new ewkDB())
     {
         return(db.GetTable <T>().ToList());
     }
 }
 public static void DeleteEntity <T>(T entity) where T : class
 {
     using (var db = new ewkDB())
     {
         db.Delete <T>(entity);
     }
 }
 public static void InsertEntityBySP <T>(string email) where T : class
 {
     using (var db = new ewkDB())
     {
         db.ExecuteProc("insert_account", DataParameter.VarChar("email", email));
     }
 }
 public static object InsertEntity <T>(T entity) where T : class
 {
     using (var db = new ewkDB())
     {
         return(db.InsertWithIdentity <T>(entity));
     }
 }
Exemplo n.º 5
0
 public void IsEqualValue([Values(ProviderName.PostgreSQL)] string configString)
 {
     using (var db = new ewkDB(configString))
     {
         var result = from a in db.accounts where a.email.Equals("*****@*****.**") select a;
         Console.WriteLine("result = {0}", result.ToList().Count);
     }
 }
Exemplo n.º 6
0
 public void TruncateAccount()
 {
     using (var db = new ewkDB(ProviderName.PostgreSQL))
     {
         db.Execute("TRUNCATE account CASCADE");
         //GenericCRUD.DeleteEntity<account>(db.accounts);
     }
 }
 public static bool IsEqualEmail(string email)
 {
     using (var db = new ewkDB())
     {
         var result = from account_ in db.accounts where account_.email.Equals(email) select account_;
         return(result.ToList().Count > 0);
     }
 }
        //public static List<T> GetEntitiesByParameters<T>(Func<T, bool> where) where T : class
        //{
        //    using (var db = new ewkDB())
        //    {
        //        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 ewkDB())
            {
                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());
            }
        }
Exemplo n.º 9
0
        public void InsertAccountBySP([Values(ProviderName.PostgreSQL)] string configString)
        {
            int    id_count       = 0;
            string template_email = "test_{0}[email protected]";

            using (var db = new ewkDB(configString))
            {
                for (int i = id_count; i < 200000; ++i)
                {
                    db.ExecuteProc("insert_account", DataParameter.VarChar("email", string.Format(template_email, i)));
                }
            }
        }
Exemplo n.º 10
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 ewkDB())
            {
                var data = db.GetTable <T>().Where <T>(expression).ToList();
                return(data);
            }
        }
Exemplo n.º 11
0
        void TestLinqToDbWithAccount()
        {
            using (var db = new ewkDB())
            {
                //var id = db.InsertWithIdentity<Account>(new Account() { EMail = "*****@*****.**", FirstSignedDate = DateTime.Now });
                //Console.WriteLine("id = {0}", id);

                db.ExecuteProc("test_insert", DataParameter.VarChar("email", "*****@*****.**"));

                List <account> list;// = TestLinq2Db.All();

                var query = from p in db.accounts
                            //where p.ProductID > 25
                            select p;
                list = query.ToList();

                foreach (account p in list)
                {
                    Console.WriteLine(p.email);
                }
            }
        }