S
Steve Richter
Am I able to/how do I pass a multi line lambda to the Where method of
a Linq.Table? When I try it, I get the error "lambda expression with a
statement body cannot be converted to an expression tree".
( p.s. I find lambdas much easier to read in a book than to write
myself. )
private pcarDataContext db = new pcarDataContext();
// this compiles and works:
public IQueryable<AccountMasterRow> FindAccountMasterRows(
string InLikeName )
{
string s1 = InLikeName.ToLower();
return db.AccountMasterRows.Where(r => r.FullName.ToLower
().IndexOf(s1) >= 0);
}
// the multiline lambda here gives the "cannot be converted to an
expression tree" error.
public IQueryable<AccountMasterRow> FindAccountMasterRows(
string InLikeName)
{
string s1 = InLikeName.ToLower();
return db.AccountMasterRows.Where(
(r) => {
int rv = r.FullName.ToLower().IndexOf(s1);
if (rv >= 0)
return true;
else
return false;
}
) ;
}
a Linq.Table? When I try it, I get the error "lambda expression with a
statement body cannot be converted to an expression tree".
( p.s. I find lambdas much easier to read in a book than to write
myself. )
private pcarDataContext db = new pcarDataContext();
// this compiles and works:
public IQueryable<AccountMasterRow> FindAccountMasterRows(
string InLikeName )
{
string s1 = InLikeName.ToLower();
return db.AccountMasterRows.Where(r => r.FullName.ToLower
().IndexOf(s1) >= 0);
}
// the multiline lambda here gives the "cannot be converted to an
expression tree" error.
public IQueryable<AccountMasterRow> FindAccountMasterRows(
string InLikeName)
{
string s1 = InLikeName.ToLower();
return db.AccountMasterRows.Where(
(r) => {
int rv = r.FullName.ToLower().IndexOf(s1);
if (rv >= 0)
return true;
else
return false;
}
) ;
}