The Linq IEnumerable <TEntity> expression does not contain a definition of where
How to write the correct Linq expression used in generic for the where clause
public static class ConStr { public static MySqlConnection Conn() { return new MySqlConnection(ConfigurationManager.ConnectionStrings["DBCN"].ConnectionString); } } Repositor.cs
private IDbConnection cn; public IEnumerable<TEntity> FilterBy(Expression<Func<TEntity, bool>> expression) { using(cn = ConStr.Conn()) { return cn.GetAll<TEntity>(null).Where(expression); <--error does not contain definition of where } } but this with a linq expression will work
using (IDbConnection cn = ConStr.Conn()) { var que = cn.GetAll<Cause>(null).Where(x=>x.cause_id == 1); bool dbIE = Utils.IsAny<Cause>(que); if (dbIE == true) { DGRID.DataSource = que; } else { MessageBox.Show("Sorry No Value"); } } +5
1 answer
Where for IEnumerable<T> does not contain an overload that accepts Expression . To use Where with Expression , you must change the result of GetAll to IQueryable . For your specific case, you can simply change Expression<Func<TEntity, bool>> expression to Func<TEntity, bool> expression , and everything should work.
+4