Question

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?

Était-ce utile?

La solution

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());
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top