This is my linq query (Linq to Sql) :
pagina = (from Pagine page in kDataBase.Pagines
where prova(page.title_it) == urlSuddivisa[i].ToLower()
select page).FirstOrDefault();
and this is the function I call (inside the same class) :
private string prova(string example)
{
return example;
}
it says :
there are not supported conversion to sql for the method ‘System.String prova(System.String).
Where am I wrong? And how can I fix it?
Since the linq query is converted into a SQL query that runs against your dB it is not able to translate your custom function into a SQL query.
Alternative ways of appraoaching the problem
retrieve your data from SQL to memory and then filter it based on your function. The disadvantage obviously here is you will be retrieving a lot many number of rows from the database than what is required
var paginas=(from Pagine page in kDataBase.Pagines).ToList().Where(p =>prova(p.title_it) == urlSuddivisa[i].ToLower()).FirstOrDefault();is what you want.
On a side note I am guessing your method
provadoes more than just returning the string otherwise the function is outright useless and you may as well get rid of the function. Also I believe you are firing multiple queries to the database cos of the array that you are using with a counteriyou could always use theINquery and get around it, remember the restriction of the number of element in anINquery.