Expression tree question

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!
 
M

Marcel Müller

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
 
C

Chris Hardie

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

Regards,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top