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

13 posts, 0 answers
  1. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 23 Feb Link to this post

    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.

  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 26 Feb Link to this post

    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.
  3. DevCraft banner
  4. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 01 Mar Link to this post

    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.
  5. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 04 Mar in reply to Thomas Link to this post

    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

  6. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 07 Mar Link to this post

    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.
  7. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 08 Mar Link to this post

    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

  8. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 17 Mar Link to this post

    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.
  9. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 17 Mar in reply to Thomas Link to this post

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

    Cheers

     

  10. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 28 Apr in reply to RIT Link to this post

    Hi Thomas

    When is the next NuGet release scheduled? 

    Thanks

  11. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 03 May in reply to Thomas Link to this post

    We are close to a release window, is there anything planned on your side? Thanks
  12. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 04 May Link to this post

    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.
  13. RIT
    RIT avatar
    21 posts
    Member since:
    Apr 2015

    Posted 11 Aug in reply to Doroteya Link to this post

    We have another release window soon. Is there anything planned on your side?
  14. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 11 Aug Link to this post

    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.
Back to Top
DevCraft banner