Hi, anyones knows how to do this?
Edit: I am trying to do >=. I correct the Title.
Hi, anyones knows how to do this?
Edit: I am trying to do >=. I correct the Title.
string1 => string2 is not supported in C# LinqToSql or not. The String class does not override the => operator at all. It only overrides the != and == operators. You can verify this by trying to compile the following method
public static void Example() {
int val = "foo" => "bar";
}
If you want to compare to Strings in LinqToSql you should be able to use the static String.Compare(string,string) method.
I'm not exactly sure what you're trying to do here, but strings directly translate to Linq to SQL queries.
Could you give an example of what you're attempting?
Here's a basic example usage:
string string2 = "test";
using (MyDataContext dc = new MyDataContext())
{
// without lambdas
var query1 = from item in dc.Items
where item.Value == string2
select item;
// with lambdas
var query2 = dc.Items.Where(item=>item.string1 == string2);
}
I am not quite sure what => than is or what language you are talking about, but I can only guess you are referring to >= (greater than or equal). You cannot use a greater than or equal operator with strings, because there is not definitive way to tell what you are talking about. If they are actually numbers you may want to do.
var query = from c in dc.Customers
where c.CustomerID >= Int32.Parse("32")
select c;
If you're looking for =>
which would normally be written as >=
then you cannot do this directly with strings. You can get the same behaviour via CompareTo:
string1.CompareTo(string2) >= 0
In this case, the result being less than or equal to zero means that string1
would be sorted before string2
and therefore is greater.
FYI the =>
operator in C# is only used in the definition of lambda expressions.
Linq to SQL does not support String.Compare - see here: http://msdn.microsoft.com/en-us/library/bb882672.aspx
I am at a loss as to how to perform this type of comparison??? Any more ideas?
I did a blog post about Binary Comparison with Linq To Sql that applies to string as well as any other SQL type.
For more information go to: http://diegofrata.wordpress.com/2009/11/18/linq-to-sql-expression-trees-and-binary-comparing/