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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:28:05+00:00 2026-05-27T00:28:05+00:00

I just recently switched out our repository and context from Linq-to-SQL to Entity Framework

  • 0

I just recently switched out our repository and context from Linq-to-SQL to Entity Framework 4.1 CodeFirst.

All my unit tests are passing at the moment, except one! And that is the one that checks if I get a distinct result from a SQL-view.

var query = worker.ObjectRepository.GetFreeObjects();
query = query.Distinct();
return query;

When I inspect the query just before I call .Distinct(), the query is correct and it runs fine when I execute it manually on SQL Server.

But after I call .Distinct(), the query just looks the exact same as before.

If I manually add a DISTINCT to my SQL query, it works fine, but calling .Distinct() in code doesn’t do this.

Why is that?

Edit

public IQueryable<SearchResultValueObject> GetFreeObjects()
{
    return Get(Context.FreeObjects)
}

public IQueryable<TEntity> Get<TEntity>(IQueryable<TEntity> query)
{
    return query;
}

I simplyfied a bit becaus at this scenario that’s all that is happening. Grabbing the data from the Context, and returning it.

This is how my Context look

public class MyContext : DbContext, IMyContext
{
    public virtual DbSet<SearchResultValueObject> SearchResult { get; set; }

    IQueryable<SearchResultValueObject> IMyContext.FreeObjects { get { return this.SearchResult; } }
}

I also tried to remove everything except the objectNo from the SearchResultMap-file, I got the results from the Db, but .Distinct() didn’t work.

Edit2

I made a simple example that has the same problem: http://pastebin.com/sYVfNb0Y
Does this has something to do with the fact that I’m fetching from a view? Or am I missing something important here?

Best regards
Jesper

  • 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-27T00:28:06+00:00Added an answer on May 27, 2026 at 12:28 am

    I would love it if someone could find a way around this. But after several hours of looking around it all came down to me making a new view based on the old view.

    I don’t know if it’s the right way to do it, but it helped me with my problem.

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

Sidebar

Related Questions

I just recently changed out all my hard drives and in the process of
We just recently migrated our web application from .NET 1.1 to .NET 2.0. The
We just recently switched from Visual Studio 2008 to Visual Studio 2010. I have
We've just recently switched over from SVN to Mercurial, but now we are running
Recently I switched my templating engine from default to Jinja2/Coffin. Everything works just fine
Just recently I switched the language of my project to use C++ from C.
I just recently noticed Dictionary.TryGetValue(TKey key, out TValue value) and was curious as to
We've just recently switched to VS 2010 and i had a solution that was
We recently switched our webapp to use SSL at the request of a very
I recently switched from ipython0.10 to ipython0.11. In ipython0.11, I only see a small

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.