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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:47:28+00:00 2026-06-02T14:47:28+00:00

Using MySQl 5.5.19, entity framework 4.3, and have tried both the Sun-provided MySQL connector

  • 0

Using MySQl 5.5.19, entity framework 4.3, and have tried both the Sun-provided MySQL connector and the DevArt one without any difference between the two.

So, I’ve got two statements which produce different queries. The first is:

var desserts = context.desserts
    .AsQueryable()
    .OrderBy(m => m.Id)
    .Where(m => m.FlavorId == 123)
    .ToList();

and the second is

var desserts = context.desserts
    .AsQueryable()
    .OrderBy(m => m.Id)
    .Where(m => m.FlavorId == someFlavorId)
    .ToList();

The first query produces a SQL query that looks something like this:

SELECT
  Extent1.Id,
  Extent1.Name,
  Extent1.FlavorId
FROM icecream.dessert AS Extent1
WHERE Extent1.FlavorId = 123
ORDER BY Extent1.Id ASC

The second one produces a much more costly query that looks something like this:

SELECT
  Project1.Id,
  Project1.Name,
  Project1.FlavorId
  FROM(
    SELECT
      Extent1.Id,
      Extent1.Name,
      Extent1.FlavorId
    FROM icecream.dessert AS Extent1
    WHERE Extent1.FlavorId = 123
  ) AS Project1
  ORDER BY Project1.Id ASC

And, of course, the latter query is the one that is used in my production code. I’m confused why these two result in a different query.

Any ideas how to fix this?

  • 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-02T14:47:35+00:00Added an answer on June 2, 2026 at 2:47 pm

    They produce different sql, because the first query you are passing in a constant and the second one you are passing in a parameter.

    If you want to mimic the first query you would need to create an Expression for the Where predicate like this:

    ParameterExpression parameter = Expression.Parameter(typeof(Dessert), "d");
    Expression propertyOrField = Expression.PropertyOrField(parameter , "FlavorId");
    Expression constant = Expression.Constant(someFlavorId, typeof(long?));
    Expression equal = Expression.Equal(propertyOrField, constant);
    
    var lambda = Expression.Lambda<Func<Dessert, bool>>(equal, parameter);
    
    var desserts = context.desserts
        .AsQueryable()
        .OrderBy(m => m.Id)
        .Where(lambda)
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use MySQL (5.5.22, Connector 6.5.4) with Entity Framework 4. I'm using
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I have a WPF application in which I use entity framework with mysql connector/net
I'm using entity framework and mysql as a backend. I have an entity that
I'm trying to make sense of a situation I have using entity framework on
I'm using MySQL with ASPNET and Membership (including Entity Framework), also with autogenerateschema=true with
I'm using Entity Framework to access my MySQL database. The model was generated using
I have an application that contains methods that work with data using Entity Framework
I am using MySQL .net connector 6.4.4.0 and Entity Frame work 4.1 and trying
I have a simple app written using SQL Server, Entity Framework, C# and WCF.

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.