Expression tree question

  • Thread starter Thread starter Chris Hardie
  • Start date Start date
C

Chris Hardie

Hi,

For kicks I'm building expression trees to query my linq-to-entities
provider. Everything works fine, except for one WHERE clause
constraint that I don't know how to build. I want to check to see if
some text is contained in the memo field, but I haven't the faintest
idea how to do that.

ParameterExpression pe =
Expression.Parameter(typeof(LogBookTransaction), "log");

IQueryable queryableData = context.LogBookTransactions.AsQueryable();

Expression left = Expression.Property(pe,
typeof(LogBookTransaction).GetProperty("EmployeeNumber"));
Expression right =
Expression.Constant(Decimal.Parse(selEmployee.SelectedValue),
typeof(decimal);
Expression e1 = Expression.Equal(left, right); //Here i check to
ensure equality

Expression left = Expression.Property(pe,
typeof(LogBookTransaction).GetProperty("Memo"));
Expression right = Expression.Constant(txtSearch.Text,
typeof(string));
Expressions e2 = ??? //There is no Expression.Contains method

***SNIP***

I'm looking for how to do the following in SQL:

WHERE memo LIKE '%myText%'

Any ideas?

Thanks!
 
Expressions e2 = ??? //There is no Expression.Contains method

You need to call the Contains function of the string class. So your
expression is of type method call.


Marcel
 
Cool, thanks. Can you point me to where I can find some simple syntax
for a noob?

Regards,

Chris
 
Back
Top