locked
SELECT TOP (1) .... by Entity Framework RRS feed

  • Question

  • Hi guys,

     

    I have a weird problem here.  I have 2 identical edmx mapped from a database.  edmx_1 is generated by me and edmx_2 is generated by someone else (both are mapped from the same database)

     

    edmx_1

    TableA table = (from t in context

    where t.ID == 10

    select t).FirstOrDefault();

    sql statement generated by entity framework: SELECT TOP 1 . . . . .

     

     

    edmx_2

    TableA table = (from t in context

    where t.ID == 10

    select t).FirstOrDefault();

    sql statement generated by entity framework: SELECT TOP (1) . . . . .

     

    As you can see, both edmx are mapped from the same database, but why the sql generated by both edmx are different?  Also edmx_2 generated "SELECT TOP (1)" statement is not valid and will return error.

     

    What do you guys think?

    Sunday, August 31, 2008 6:02 PM

Answers

  • Can you open edmx in notepad and tell me what is the value of "Provider" and "ProviderManifestToken" attributes?

     

    They should be identical, given that edmx was generated from the same database, but those are pretty much the only outside "variables" that can impact the generated query, so I suspect a difference there.

     

    Jarek

    Monday, September 1, 2008 3:52 AM

All replies

  • Very strange! Are you sure it's really the same edmx?

    Copy Paste the edmx xml from edmx_1 to edmx_2 and test again.

    Sunday, August 31, 2008 7:40 PM
  • But, how come entity frame work generate such sql statement? SELECT TOP (1)? This is not a correct syntax, right?

     

     

     MatthieuMEZIL wrote:

    Very strange! Are you sure it's really the same edmx?

    Copy Paste the edmx xml from edmx_1 to edmx_2 and test again.

    Monday, September 1, 2008 12:57 AM
  • Can you open edmx in notepad and tell me what is the value of "Provider" and "ProviderManifestToken" attributes?

     

    They should be identical, given that edmx was generated from the same database, but those are pretty much the only outside "variables" that can impact the generated query, so I suspect a difference there.

     

    Jarek

    Monday, September 1, 2008 3:52 AM
  • You are right.

     

    edmx_1, ProviderManifestToken = 2000 and edmx_2, ProviderManifestToken = 2005.  This explain why the output is different.

     

    Thanks... Smile

     

     

     Jaroslaw Kowalski - MSFT wrote:

    Can you open edmx in notepad and tell me what is the value of "ProviderManifest" and "ProviderManifestToken" attributes?

     

    They should be identical, given that edmx was generated from the same database, but those are pretty much the only outside "variables" that can impact the generated query, so I suspect a difference there.

     

    Jarek

    Monday, September 1, 2008 2:38 PM
  • can some one tell me how to change the

    ProviderManifestToken from 2005 to 2000.

    I have been developing using 2005 but the target database is 2000

    Thanks!

    Thursday, January 7, 2010 11:19 PM