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();
}
}
Where Clause in Query Syntax: The where clause is used to filter the query according to the given condition. You can provide a condition to where clause using lambda expression or by using Func delegate type. Where clause supports query syntax in both C# and VB.Net languages.
A single query expression may have multiple where clauses.
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.
The problem you're having is that because the query needs to be ran on the database, you can only use things that will work on the database, the C# code in your isUser
method can't run on the database.
You'll have to re-write it without using that function. Perhaps you have a table listing users by IDs you could join on?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With