Ejemplo n.º 1
0
        public virtual IEnumerable <T> Find(Expression <Func <T, bool> > predicate)
        {
            IEnumerable <T> items = null;

            if (items == null || items.Count() == 0)
            {
                // extract the dynamic sql query and parameters from predicate
                QueryResult result = DynamicQuery.GetDynamicQuery <T>(this.tableName, predicate);
                using (DbConnection cn = this.Connection)
                {
                    cn.Open();
                    items = cn.Query <T>(result.Sql, (object)result.Param);
                }
            }

            if (items != null && items.Count() > 0)
            {
                items = items.Where(predicate.Compile());
            }

            return(items);
        }
 /// <summary>
 /// This method is used to construct the update statement based on the entity type.
 /// </summary>
 /// <typeparam name="T">Represents entity Type</typeparam>
 /// <param name="cnn">Represents SQL connection object</param>
 /// <param name="tableName">Name of the table which update statement performs</param>
 /// <param name="param">Represents Parameters collection</param>
 public static void Update(this DbConnection cnn, string tableName, dynamic param)
 {
     SqlMapper.Execute(cnn, DynamicQuery.GetUpdateQuery(tableName, param), param);
 }
        /// <summary>
        /// This method is used to construct the insert statement based on the entity type.
        /// </summary>
        /// <typeparam name="T">Represents entity Type</typeparam>
        /// <param name="cnn">Represents SQL connection object</param>
        /// <param name="tableName">Name of the table which insert statement performs</param>
        /// <param name="param">Represents Parameters collection</param>
        /// <returns>Primary key</returns>
        public static T Insert <T>(this DbConnection cnn, string tableName, dynamic param)
        {
            IEnumerable <T> result = SqlMapper.Query <T>(cnn, DynamicQuery.GetInsertQuery(tableName, param), param);

            return(result.First());
        }