0

When I attempt the following:

   public List<MatterViewModel> ReturnMatchingMatters(IEnumerable<string> matterNames)
    {
        var filter = PredicateBuilder.True<tblMatter>();
        filter = x => matterNames.Any(mattername => mattername.ToLowerInvariant() == x.Matter.ToLowerInvariant());

        return this.dal.DB.GetList<MatterViewModel>(OrmLiteConfig.DialectProvider.ExpressionVisitor<tblMatter>().Where(filter).ToSelectStatement());
    }

I receive the error:

variable 'x' of type '[...]tblMatter' referenced from scope '', but it is not defined ([...] mine)

Essentially, what I'm trying to accomplish is to have the predicate return true if the matter string is contained within any of the matters.

What am I missing? Do I need to do some sort of foreach with a temp variable?

Gray
  • 115,027
  • 24
  • 293
  • 354
SeanKilleen
  • 8,809
  • 17
  • 80
  • 133
  • Don't know if it matters, but `var filter = PredicateBuilder.True();` is dead code, because you immediately re-assign the filter variable. I would try to remove noise first, i.e. directly put the lambda in the Where. – Gert Arnold Oct 25 '13 at 20:07
  • Is this ormlite-servicestack? I've updated the tags. – Gray Dec 17 '13 at 17:01

1 Answers1

1

The following code accomplishes what I need to do, though might not be the prettiest.

    public List<string> ReturnMatchingMatters(IEnumerable<string> matterNames)
    {

        var filter = PredicateBuilder.True<tblMatter>();
        filter = x => Sql.In(x.Matter, matterNames);

        SqlExpressionVisitor<tblMatter> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor<tblMatter>();

        ev.Select("select Matter from tblmatter");
        ev.Where(filter);

        return this.dal.DB.GetList<string>(ev.ToSelectStatement());
    }
SeanKilleen
  • 8,809
  • 17
  • 80
  • 133