Page 1 of 1

Does LinqConnect support custom comparer for OrderBy?

Posted: Tue 18 Aug 2015 15:45
by costashu
I use LinqConnect Express Edition 4.5.802.0. For comparer:

Code: Select all

public class CaseInsensitiveComparer : IComparer<string>
{
    public int Compare(string x, string y)
    {
        return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
    }
}
and query:

Code: Select all

var q1 = (from b in a.Words
    from c in b.Sources
    from d in c.Pairs
    select new { word = b.Word, source = c.Source, target = d.Target.Target })
    .OrderBy(x => x.word, new CaseInsensitiveComparer());
foreach (var z in q1)
exception is thrown in foreach:

Code: Select all

System.NotSupportedException was unhandled
  HResult=-2146233067
  Message=Unsupported overload used for query operator 'OrderBy'.
  Source=Devart.Data.Linq
  ...
Without "new CaseInsensitiveComparer()" in OrderBy, everything works.

Re: Does LinqConnect support custom comparer for OrderBy?

Posted: Wed 19 Aug 2015 11:59
by MariiaI
LinqConnect as well as standard LINQ to SQL (LINQ to SQL Classes model with SQL Server) don't support such scenarios.
However, the possible solution is described here. In your case, you should try re-writing your query this way:

Code: Select all

var q1 = (from b in a.Words
    from c in b.Sources
    from d in c.Pairs
    select new { word = b.Word, source = c.Source, target = d.Target.Target })
    .AsEnumerable()
    .OrderBy(x => x.word, new CaseInsensitiveComparer());
foreach (var z in q1)

Re: Does LinqConnect support custom comparer for OrderBy?

Posted: Wed 19 Aug 2015 15:56
by costashu
Thank you! Now I'm using ".ToLower(new CultureInfo(sourceCulture)" instead of a custom comparer and your advice works too. Excellent!

Re: Does LinqConnect support custom comparer for OrderBy?

Posted: Thu 20 Aug 2015 05:19
by MariiaI
Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.