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

  • Home
  • SEARCH
  • 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 5928787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:20:01+00:00 2026-05-22T14:20:01+00:00

I am using a view to return a complex search query. When I usin

  • 0

I am using a view to return a complex search query. When I usin linq to query against EF it is returning the same row 3 times(the actual rowcount is correct).

using LinqPad I have run the same linq against my ef entity and the actual database view.

ReadmitPatientList
    .AsQueryable()
    .Where("PatientLastName.StartsWith(\"cooper\")")
    .OrderBy (rpl => rpl.PatientLastName)
    .Dump();

That is the linq I am using for both.

linqpad shows the lambda as this:
EF:

ReadmitPatientList.MergeAs (AppendOnly)
   .Where ( => .PatientLastName.StartsWith ("cooper"))
   .OrderBy (rpl => rpl.PatientLastName)

DB

ReadmitPatientList
   .Where ( => .PatientLastName.StartsWith ("cooper"))
   .OrderBy (rpl => rpl.PatientLastName)

I cannot post the results…but EF returns three rows of the same record. DB returns 3 rows of individual records. As does my sql query.

What about my EF LINQ do I need to change to make it work correctly?


The sql code that is generated by the EF Linq query Actually returns the correct results if run in SQL explorer.

  • 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-05-22T14:20:02+00:00Added an answer on May 22, 2026 at 2:20 pm

    This happens if Patient entity doesn’t have primary key or columns inferred as primary key are same across multiple records in the result set. EF uses internally identity map which requires that each uniquely identified record must reuse the same instance of the entity. So if you return three records from the database which have same unique identification for EF will return enumeration of three same instances representing the first record from the result set (more about identity map also here). The same behaviour is in Linq-to-sql’s DataContext.

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

Sidebar

Related Questions

Is using view in db design right method or we should handle it code
I'm trying to create a page by using view 2. This page list all
In my View (using Zend_View so the the view is an object), I make
I have a view using a master page that contains some javascript that needs
I wanted to generate one fix view using interface builder, but the size of
What pros(positive sides) of using Spark view engine for ASP.NET MVC project. Why it
I developed an Eclipse plugin (a view) using the plugin development version of Eclipse.
I am using gesture detector to catch flings and using a view flipper to
I wonder if I can test landscape view using simulator?
Well i have a complex form view model like this : public class TransactionFormViewModel

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.