Pass parameter to Expression<Func<TEntity, bool>> filter …

3 posts, 0 answers
  1. Jesus
    Jesus avatar
    4 posts
    Member since:
    Nov 2013

    Posted 18 Dec 2014 Link to this post

    I am using GenericRepository with this code ...  

    public virtual IEnumerable<TEntity> Get(
        Expression<Func<TEntity, bool>> filter = null,
        Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
        string includeProperties = "")
        IQueryable<TEntity> query = dbSet;
        if (filter != null)
            query = query.Where(filter);
        query = includeProperties.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
        return orderBy != null ? orderBy(query).ToList() : query.ToList();

    And I want use this function in my Controller ...

    public ActionResult Hojas_Read([DataSourceRequest] DataSourceRequest request)
        var usuario = _utHojas.UsuariosRepository.Get(u => u.Correo == User.Identity.Name).FirstOrDefault();

    And in my debug window appears...

    {u => (u.Correo == value(TaxiMetro.Web.Controllers.HojasController).User.Identity.Name)}

    And it should be...

    {u => (u.Correo == ""}

     How I can fix this?


  2. Jesus
    Jesus avatar
    4 posts
    Member since:
    Nov 2013

    Posted 19 Dec 2014 in reply to Jesus Link to this post

    I answer myself ...
    var name = User.Identity.Name;
    ParameterExpression param = Expression.Parameter(typeof (Usuario), "h");
    Expression boby = Expression.Equal(Expression.PropertyOrField(param, "Correo"),
          Expression.Constant(name, typeof(string)));
    Expression<Func<Usuario, bool>> filter = Expression.Lambda<Func<Usuario, bool>>(boby, param);

    var usuario = _utHojas.UsuariosRepository.Get(filter).FirstOrDefault();
  3. Boyan
    Boyan avatar
    100 posts

    Posted 22 Dec 2014 Link to this post

    Hi Jesus,

    Thank you for contacting us.

    I am glad that currently things are working on your side. If you experiencing any further Telerik Data Access related issues do not hesitate to get back to us.

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top