Generated LINQ with distinct is not OK!

2 posts, 0 answers
  1. Marko Gluhak
    Marko Gluhak avatar
    68 posts
    Member since:
    Apr 2006

    Posted 11 May Link to this post

    Hi,

    I have 2 classes that are connected over navigation properties. Publication has 0 ... many Articles.

    I have this code:

    context.Publications.Join(context.Articles.Where(itm => itm.DateTimePublished < DateTime.Now.Date)
        , pub => pub.IdPublication
        , art => art.IdPublication
        , (pub, art) => new { Publication = pub, Article = art })
    .Where(itm => itm.Publication.DateTimePublished < DateTime.Now.Date)
    .Select(itm => itm.Publication)
    .Distinct()

    Result that DataAccess gives me is:
    SELECT
    a.[IdPublication] AS COL1, a.[DateTimePrinted] AS COL2, a.[DateTimePublished] AS COL3, a.[Description] AS COL4, a.[NumberInYear] AS COL5, a.[PicturePath] AS COL6, a.[SEODescription] AS COL7, a.[SEOKeywords] AS COL8, a.[ShortDescription] AS COL9, a.[Title] AS COL10, a.[Year] AS COL11
    FROM [Publication] a
    JOIN [Article] AS b ON (a.[IdPublication] = b.[IdPublication])
    WHERE
    b.[DateTimePublished] < @p0
    AND a.[DateTimePublished] < @p1
    ORDER BY COL1

     

    WHERE IS DISTINCT WORD?!?!?

    I'm using 2015.1.225.1 version (last with Visual Designer)

    Marko

  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 17 May Link to this post

    Hello Marko,

    Telerik Data Access will apply the DISTINCT keyword if you are selecting a single persistent property mapped to a .Net primitive type. If you would like to return distinct result set of a complete persistent, please use the .Distinct(IEqualityComparer<T>) overload and provide specific to your needs implementation.
    The overload with comparer will be executed in-memory so you should expect increased network traffic as multiple complete records will be returned before being filtered out using the Distinct().

    Regards,
    Viktor Zhivkov
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
Back to Top