Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:46:39+00:00 2026-06-17T16:46:39+00:00

I have a strange problem with Linq to Entities sometimes generating graphs with duplicates.

  • 0

I have a strange problem with Linq to Entities sometimes generating graphs with duplicates.
A query, using includes, with a simple restriction at the base of the graph requested does not generate duplicates.

When the same query is used with another restriction elsewhere in the graph I have duplicates.

Consider the following graph :

Entity1
  Entity2
    Entity3
      Entity4
         Entity5
           Entity6
      Entity7
      Entity8

Now, this query :

var query = context.Entity1.Where(u => (u.StringProp.StartsWith(someValue)));
query = query.Include(@"NavpropEntity2.NavPropEntity3.NavPropEntity4.NavPropEntity5.NavEntity6");
query = query.Include(@"NavpropEntity2.NavPropEntity3.NavPropEntity7");
query = query.Include(@"NavpropEntity2.NavPropEntity3.NavPropEntity8");

does not generated duplicates for entity6 in the graph.

But the following query does !

query = context.Entity1.Join(context.Entity3, u => u.Entity2.Entity3.Entity4Id, g => g.Id, (u, g) => new NotSoAnonymousTypeWithParameterLessConstructor { Entity4= g, Entity1 = u })
                                .Where(
                                    ApplyNotSoAnonymousTypeRestrictions(
                                    StringProp,
                                    Id)
                                ).Select(z => z.Entity1);
    query = query.Include(@"Navprop1.NavProp2.NavProp3.NavProp4.NavProp5");
    query = query.Include(@"Navprop1.NavProp2.NavProp3.NavProp6");
    query = query.Include(@"Navprop1.NavProp2.NavProp3.NavProp7");

generates duplicates for Entity6.

Please note that the entity graph have the issue right at the end of the linq query.
So this is an EF/STE issue not a STE issue.

This is an issued when the graph is sent back to the server to persist changes as explained in this blog post.

I hope someone encountered the same problem and have found a solution.
TIA.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:46:40+00:00Added an answer on June 17, 2026 at 4:46 pm

    The problem arise when using the AsNoTracking() Extension introduced in EF5. This has nothing to do with the query structure. My data access code is generated from templates (.tt), we encountered the same problem today and I was able to compare one method that returned no duplicates with another one that was. The only difference was that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange problem with a LINQ to Entities query with EF1.
I have a strange problem. I do this query in a node.js server using
I have a strange problem when deleteting records using linq, my suspicion is that
I'm having a strange problem with a linq query. I'm using LINQPad 4 to
I have a strange problem. I am trying to update some fields using linq
I have strange problem with receiving data from socket. On client im using air
I have a strange problem on ipv6 connection. I write down a simple client
I have found strange behavior of IEnumerable. When i create a collection using Linq
I have strange problem on my pc/server. I run query such as Select field1,
I have a problem with strange generated SQL in ef4 ctp5. I have simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.