Below is the code I’m using but it replies with
Method ‘Boolean isUser(System.String)’ has no supported translation to SQL.
Any help? Btw I’m using linq to SQL data source
public void dataBind()
{
using (var gp = new GreatPlainsDataContext())
{
var emp = from x in gp.Employees
let k = isUser(x.ID)
where x.ActivtyStatus == 0
&& isUser(x.ID) != false
orderby x.ID
select new
{
ID = x.ID,
Name = x.FirstName + " " + x.MiddleName
};
ListView1.DataSource = emp;
ListView1.DataBind();
}
}
public static bool isUser(string ID)
{
int temp;
bool x = int.TryParse(ID, out temp);
return x;
}
I found a solution to query the result of the first query as objects but is that good cause I will passing through my data twice.
the updated code that worked in the end after using the like as advised by Anders Abel
public void dataBind()
{
using (var gp = new GreatPlainsDataContext())
{
var emp = from x in gp.Employees
where x.ActivtyStatus == 0
&& SqlMethods.Like(x.ID, "[0-9]%")
orderby x.ID
select new
{
ID = x.ID,
Name = x.FirstName + " " + x.MiddleName
};
ListView1.DataSource = emp;
ListView1.DataBind();
}
}
Linq-to-sql translates the query into SQL. It only knows how to translate a limited set of built in functions. You have to rewrite your query to not include a function of your own.
A complete list of the linq-to-sql supported functions and operators can be found at MSDN.
You can use
SqlMethods.Like()to check if the field only contains digits. See T-SQL IsNumeric() and Linq-to-SQL for an example.