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 7886733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:23:38+00:00 2026-06-03T05:23:38+00:00

I have a view where one of the joined columns is nullable but is

  • 0

I have a view where one of the joined columns is nullable but is often the only distinguishing item between two rows. I see that EF built a primary key out of all the non-nullable items in the view. I’ve noticed that when I pull from the view, this nullable column does not always get returned correctly, and I read that it has to do with the way it maps to the key, and will return the same row if it sees the key already exists.

Ideally the best solution would be to make my column not-nullable, but I can’t do that without causing larger problems.

The other idea was to use ROW_NUMBER() to make a primary key. I am unsure whether that may cause similar issues (if the context isn’t refreshed between calls, would it go solely off that or it is smart enough to realize that the queries are different?) I also worry about performance of needing an ORDER BY for the function and how that would affect dynamic ordering of the rows.

What is the best way to ensure all my rows are returned exactly as they appear through the SQL query with the least hit to performance?

Thank you..

Example:

view: A int, B int, C int?

SQL Results:
1, 2, null
1, 3, 10
1, 3, 11

EF will return something like :

1, 2, null
1, 3, 10
1, 3, 10

I need to get that 11, too.

  • 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-03T05:23:39+00:00Added an answer on June 3, 2026 at 5:23 am

    This happens due to identity map pattern. By default EF keep track of already loaded entities (identified by the entity key) – if the result set contains repeating entity key EF thinks that it is the same entity as the one already loaded and it doesn’t create a new entity instance for those repeating records – instead it uses the instance created for the first record with that key. This is necessary for change tracking and for ability to save changes back to the database.

    In your case you most probably don’t want to save changes back to database because these records don’t give you necessary information to be able to do that. So load records without change tracking and it should skip identity map pattern and generate new entity instance for every record in the result set:

    context.YourEntitySet.MergeOption = MergeOption.NoTracking; 
    // Now execute your query
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two views within one .xib (one view for landscape, another for portrait).
Actually I have 4 view attached to a single view, only one view is
I have two view controllers in a single project. However, I want one of
I have two partial views: Food and Drink. I have one view with fixed
I have one view that used to display the result of my search item.
I have one view in iPhone application. In that view i added two UIImageView
I have one view controller which contains two views (redView, blueView). The views are
I have one view ,view contains two buttons and one gallery. Gallery view pleased
How would I have one view up when the iPhone is in a standard
In my application I want to have one view that holds 2 partial views.

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.