String1> = string2 not implemented in Linq to SQL, any desktop?

Does anyone know how to do this?

Edit: I'm trying to do> =. I am correcting the name.

+6
linq-to-sql string-comparison
source share
4 answers

string1> = string2 is not supported in C # Linq To Sql. The String class does not override the> = operator. It only redefines the operators! = And ==. You can verify this by trying to compile the following method

public static void Example() { int val = "foo" >= "bar"; } 

If you want to compare with strings in LinqToSql, you can use the static method String.Compare (string, string) .

+7
source share

If you are looking for => , which is usually written as >= , you cannot do this directly with strings. You can get the same behavior through CompareTo :

 string1.CompareTo(string2) >= 0 

In this case, a result less than or equal to zero means that string1 will be sorted to string2 and therefore greater.

The FYI operator => in C # is used only in the definition of lambda expressions.

+19
source share

I'm not quite sure what => what it is or what language you speak, but I can only guess what you mean> = (more or equal). You cannot use a greater or equal operator with strings, because there is no specific way to tell what you are talking about. If they really are numbers you can do.

 var query = from c in dc.Customers where c.CustomerID >= Int32.Parse("32") select c; 
+1
source share

I'm not quite sure what you are trying to do here, but strings are directly translated in Linq to SQL queries.

Could you give an example of what you are trying to do?

Here is an example using the example:

 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); } 
0
source share

All Articles