Does LinqConnect support custom comparer for OrderBy?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
costashu
Posts: 4
Joined: Tue 18 Aug 2015 14:44

Does LinqConnect support custom comparer for OrderBy?

Post by costashu » Tue 18 Aug 2015 15:45

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.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Does LinqConnect support custom comparer for OrderBy?

Post by MariiaI » Wed 19 Aug 2015 11:59

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)

costashu
Posts: 4
Joined: Tue 18 Aug 2015 14:44

Re: Does LinqConnect support custom comparer for OrderBy?

Post by costashu » Wed 19 Aug 2015 15:56

Thank you! Now I'm using ".ToLower(new CultureInfo(sourceCulture)" instead of a custom comparer and your advice works too. Excellent!

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Does LinqConnect support custom comparer for OrderBy?

Post by MariiaI » Thu 20 Aug 2015 05:19

Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.

Post Reply