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

Issues with self-referencing many-to-many relationship (when eager-loading with include)

12 Answers 67 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.
RIT
Top achievements
Rank 1
RIT asked on 23 Feb 2016, 03:57 PM

Hi

Can anyone tell me if the following issue is caused by misconfiguration or if it is a bug in DA?
We were able to reproduce this issue with all recent  and current DA NuGet versions on SQL Server 10.50.2550.0 and 12.0.2000.8. The queries and their results where analyzed with SQL profiler and are correct.

The data model is a Code-entity with m-to-m relationship on itself. The m-to-m relationship is defined by the table "CodeScope" which consists of two Code-Id FKs columns forming a primary key cluster. 

Code entity:
int Id
string Name
IList<Code> RestrictedFor
IList<Code> Restricts

MappingConfiguration:
configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Default).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Id").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0); configuration.HasProperty(x => x.Name).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Name").IsNotNullable().HasColumnType("nvarchar").HasLength(255);
configuration.HasAssociation(x => x.RestrictedFor).IsManaged().WithOpposite(x => x.Restricts).WithDataAccessKind(DataAccessKind.ReadWrite).MapJoinTable("CodeScope", (x, y) => new { Code_Id = x.Id, Scope_Id = y.Id }); 

 

Now the thing is to a certain number of entries in the code table both collections (Restricted and RestrictedFor) on all Code-entities represent the defined relationships correctly. After adding the 693th entry in the Code-table, without adding a new relationship, one collection is suddenly empty:

var codes = db.GetAll<Code>().Include(x => x.RestrictedFor).Include(x => x.Restricts);
codes.Count() // 662
codes .SelectMany(x => x.RestrictedFor).Count() // 169
codes .SelectMany(x => x.Restricts).Count() // 169

// adding a new Code to db manually, without defining new CodeScope relationship
var codes = db.GetAll<Code>().Include(x => x.RestrictedFor).Include(x => x.Restricts); // in a new context, restarted program
codes.Count() // 663
db.GetAll<Code>().SelectMany(x => x.RestrictedFor).Count() // 0 (!)
db.GetAll<Code>().SelectMany(x => x.Restricts).Count() // 169

// when loading all codes without Include, it works again..
var codes = db.GetAll<Code>();
codes.Count() // 663
db.GetAll<Code>().SelectMany(x => x.RestrictedFor).Count() // 169
db.GetAll<Code>().SelectMany(x => x.Restricts).Count() // 169

Code and SQL scripts are on GitHub: https://github.com/mkubicek/DataAccessSelfReference
Really appreciate all forms of feedback as this is a major showstopper for us. Thank you in advance.

12 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 26 Feb 2016, 07:33 AM
Hi Florian,

thanks for the report, I will have a look at it today.

Regards,
Thomas
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Thomas
Telerik team
answered on 01 Mar 2016, 08:21 AM
Hello Florian,


we are still looking into this (Many thanks for the perfect repro!). Looks like we need to review a few bits for this. Please stay tuned.

Regards,
Thomas
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
RIT
Top achievements
Rank 1
answered on 04 Mar 2016, 12:39 PM

Hi Thomas

Had you already some time to look into this? For us its a major problem, as we both need the performance of .Include and the stability. So there is currently no workaround for us (only by removing the MapJoinTable and manage the asscociation by ourself).

Best regards,

Florian

0
Thomas
Telerik team
answered on 07 Mar 2016, 01:16 PM
Hi Florian,


I'm still not done yet with thits issue. I hope to finish this this week, it needs testing on all platforms and contains a non-trivial change.
If this issue is that urgent for you, the only option i see at the moment is to avoid this prefetching .Include.
I will keep you informed about the further progress.

Regards,
Thomas
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
RIT
Top achievements
Rank 1
answered on 08 Mar 2016, 02:28 PM

Hi Thomas

Thanks for your reply. It is good to know that you are working on this. We will happy to wait another week, if the issue can be resolved.

Best regards,

Florian

0
Thomas
Telerik team
answered on 17 Mar 2016, 01:45 PM
Hi Florian,

We have fixed this issue. Thanks again for the good reproduction! I have updated your Telerik points.
Unfortunately, the fix did not make it into the build that was just finished. We plan to release a fix for your
issue mid of April. Unfortunately, there is no workaround for this but to avoid using prefetching. We are
sorry for the inconvenience this can cause.

Regards,
Thomas
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
RIT
Top achievements
Rank 1
answered on 17 Mar 2016, 02:44 PM

Thanks for the fix. Looking forward to the mid April release!

Cheers

 

0
RIT
Top achievements
Rank 1
answered on 28 Apr 2016, 03:56 PM

Hi Thomas

When is the next NuGet release scheduled? 

Thanks

0
RIT
Top achievements
Rank 1
answered on 03 May 2016, 07:57 AM
We are close to a release window, is there anything planned on your side? Thanks
0
Doroteya
Telerik team
answered on 04 May 2016, 06:28 AM
Hi Florian,

Our plan is to release Data Access Q2 2016 in the second half of the year.

Regards,
Doroteya
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
RIT
Top achievements
Rank 1
answered on 11 Aug 2016, 07:32 AM
We have another release window soon. Is there anything planned on your side?
0
Doroteya
Telerik team
answered on 11 Aug 2016, 11:21 AM
Hello RIT,

The release of Data Access Q2 2016 is planned in the September - October 2016 timeframe.

Regards,
Doroteya
Telerik by Progress
 
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
RIT
Top achievements
Rank 1
Answers by
Thomas
Telerik team
RIT
Top achievements
Rank 1
Doroteya
Telerik team
Share this question
or