ef4 ctp5に奇妙なSQLが生成されているという問題があります。ctp5とダーティーを生成したエンティティ・フレームワーク4
私はマッピングとシンプルなモデルがあります:
[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;
}
}
}
を、私のLINQクエリは次のとおりです。理由:
_rovastampDbContext.PostAuctions.Where(x => x.PostAuctionCategoryId == auctionId).OrderBy(x => x.Id).ToList();
EF4プロファイラは、私の質問は非常に単純です
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
私を示していef4は複雑なクエリを生成します。正しい場合は
あなたのアドバイスのための10のSELECT ...
FROM TABLE
WHERE CategoryId = 1
ORDER BY Id ASC
感謝:)
EDIT
マーティン:私はEFはデシベル自動作成するために聞かせている場合、クエリで問題が解決しない...
は複雑ではありません。最初はどこかORDER BY –
@Kイワノフ:必要以上に複雑です。これは、>順序を選択>投影に選択>選択します。 「投影に選択」は不要であり、クエリの実行が遅くなる可能性があります。 – StriplingWarrior
好奇心から外れて、 'IsAuctionPhotoExitst'プロパティをクラスから削除すると同じように動作しますか? – StriplingWarrior