Question

anyones knows how to do this?

Edit: I am trying to do >=. I correct the Title.

Was it helpful?

Solution

string1 >= string2 is not supported in C# Linq To Sql. 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.

OTHER TIPS

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.

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;

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top