Entity framework 4 with ctp5 and dirty generated sql

robertasunset

New Member
I have a problem with strange generate sql in ef4 ctp5.I have simple model with mapping : \[code\][Table("post_auction")]public class PostAuction{ [Key,Column(Name="Id"),DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGenerationOption.Identity)] public int Id { get; set; } [Column(Name = "Number")] public int Number { get; set; } [Column(Name = "Label")] public string Label { get; set; } [Column(Name = "Description")] public string Description { get; set; } [Column(Name = "CategoryId")] public int PostAuctionCategoryId { get; set; } [Column(Name = "PriceCZK")] public int PriceCZK { get; set; } [NotMapped] public bool IsAuctionPhotoExitst { get { if (File.Exists(HttpContext.Current.Server.MapPath("~/Public/Images/Posts/Thumbs/small_" + this.Number + ".jpg"))) return true; return false; } }}\[/code\]and my linq query is : \[code\]_rovastampDbContext.PostAuctions.Where(x => x.PostAuctionCategoryId == auctionId).OrderBy(x => x.Id).ToList();\[/code\]Ef4 profiler show me \[code\]SELECT [Project1].[Id] AS [Id], [Project1].[Number] AS [Number], [Project1].[Label] AS [Label], [Project1].[Description] AS [Description], [Project1].[CategoryId] AS [CategoryId], [Project1].[PriceCZK] AS [PriceCZK]FROM (SELECT [Extent1].[Id] AS [Id], [Extent1].[Number] AS [Number], [Extent1].[Label] AS [Label], [Extent1].[Description] AS [Description], [Extent1].[CategoryId] AS [CategoryId], [Extent1].[PriceCZK] AS [PriceCZK]FROM [dbo].[post_auction] AS [Extent1] WHERE [Extent1].[CategoryId] = 1 /* @p__linq__0 */) AS [Project1]ORDER BY [Project1].[Id] ASC\[/code\]My question is a pretty simple : Why ef4 generate that complicated query, when right one is Select ... FROM TABLE WHERE CategoryId=1 ORDERBY Id ASCThanks for your advice :)MartinEDIT : If I let ef to create db automatic, the problem with quer persists...
 
Top