This is a migrated thread and some comments may be shown as answers.

Generated LINQ with distinct is not OK!

1 Answer 43 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marko Gluhak
Top achievements
Rank 1
Marko Gluhak asked on 11 May 2016, 07:50 PM

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

1 Answer, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 17 May 2016, 01:16 PM
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.
Tags
General Discussions
Asked by
Marko Gluhak
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Share this question
or