예제 #1
0
        public List <TEntity> GetAll(Expression <Func <TEntity, bool> > predicate = null)
        {
            List <TEntity> entityList = null;

            if (predicate == null)
            {
                using (IDbConnection conn = Connection)
                {
                    conn.Open();
                    entityList = conn.Query <TEntity>("SELECT * FROM " + TableName).ToList();
                    conn.Close();
                    return(entityList);
                }
            }
            else
            {
                DynamicQueryResult result = GenerateDynamicQuery.GetDynamicQuery(TableName, predicate);
                using (IDbConnection conn = Connection)
                {
                    conn.Open();
                    entityList = conn.Query <TEntity>(result.Sql, (object)result.Parameter).ToList();
                    conn.Close();
                    return(entityList);
                }
            }
        }
예제 #2
0
        public TEntity Get(Expression <Func <TEntity, bool> > predicate)
        {
            TEntity            entity = null;
            DynamicQueryResult result = GenerateDynamicQuery.GetDynamicQuery(TableName, predicate);

            using (IDbConnection conn = Connection)
            {
                conn.Open();
                entity = conn.Query <TEntity>(result.Sql, (object)result.Parameter).FirstOrDefault();
                conn.Close();
                return(entity);
            }
        }