Print Page | Close Window

ToString() lambda expression

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2126
Printed Date: 10-Jun-2026 at 7:09pm


Topic: ToString() lambda expression
Posted By: jcrada
Subject: ToString() lambda expression
Date Posted: 03-Sep-2010 at 5:23pm
Hi

Is there any way to use ToString() methods in a lambda expression with ideablade?
I have something like this
var query = Entities.DefaultManager.GetQuery<People>().AsQueryable();

and I want to filter some integers and doubles (for example person years old and Money ) with a textbox value

String searchText = TextEdit.Text;

query = query.Where(person =>  person.YearsOld.ToString().Contains(searchText) || 
person.Money.ToString().Contains(searchText)
);





Replies:
Posted By: jcrada
Date Posted: 04-Sep-2010 at 12:52pm
Finally I Figure out a solution for the problem , you have to use

Snippet
SqlFunctions.StringConvert((Double)person.YearsOld).Contains(searchText)

this must work fine the problem is that when you execute que query Ideablade throw an exception

"Execution of query against the server was successful but execution of query against the local cache failed"
Target Site {System.String StringConvert(System.Nullable`1[System.Double])}
{"This function can only be invoked from LINQ to Entities."}

if I change the query strategy to datasource only, the query is fine, and there is No exception, is there Ideablade
support for SqlFunctions, because they work for LINQ to Entities
thanks


Posted By: sbelini
Date Posted: 09-Sep-2010 at 5:35pm
Hi,
 
Unfortunately, SqlFunctions methods have no "LINQ to Objects" implementation, they are only defined within a query against an Entity Framework backend (i.e. "LINQ to Entities").
 
As for using ToString() (in a lambda expression), since it is not supported by the Entity Framework, it can only be executed against the cache.



Print Page | Close Window