簡體   English   中英

如何加載實體框架預編譯視圖

[英]How do Entity Framework pre-compiled views get loaded

我發現通過使用EdmGen.exe工具預編譯我的視圖,我可以提高應用程序的EdmGen.exe

這是一切都很好,但是沒有我或我的大學可以工作在所產生的cs文件實際上是如何使用的項目。 似乎沒有任何關於在任何地方生成的類的引用,所以如何包含它?

任何人都可以對此有所了解,因為它真的很令人沮喪,不知道它是如何工作的!


編輯

我們已經確認EntityViewGenerationAttribute用於標記預編譯視圖的類類型,但這必須意味着它通過反射加載。 如果是這種情況,有沒有辦法明確地將它放在代碼中,預編譯的視圖類應該用於某個視圖?

您可以嘗試更改生成的代碼。 這樣就返回了一個不同的視圖。 但是如果你不返回視圖,我希望EF會失敗。

我們的想法是生成的類適用於DBContext中的所有集合。 事實上,如果視圖與您擁有的上下文(哈希比較)不匹配,您將收到運行時錯誤。

例如

   /// <Summary>
    /// The constructor stores the views for the extents and also the hash values generated based on the metadata and mapping closure and views.
    /// </Summary>
    public ViewsForBaseEntitySets24F9763E92A9F77E970A08557E1855C7579989F684539A5FB429069F966B9B7B()
    {
        this.EdmEntityContainerName = "Ef6Ctx3";
        this.StoreEntityContainerName = "CodeFirstDatabase";
        this.HashOverMappingClosure = "d7686982aa7cffcf874313838914e93f78d4d7d6d345d19261ef5edc8b4e96dd";
        this.HashOverAllExtentViews = "7b8857ee3ee44d13b2479e43c54dbdfb6bc8914e222c7891afcfcd9a29b06b2f";
        this.ViewCount = 2;
    }

但是對於給定的視圖,您可以返回不同的字符串

   /// <Summary>
    /// return view for CodeFirstDatabase.pocotest
    /// </Summary>
    private System.Collections.Generic.KeyValuePair<string, string> GetView0()
    {
        return new System.Collections.Generic.KeyValuePair<string, string>("CodeFirstDatabase.pocotest", @"
SELECT VALUE -- Constructing pocotest
    [CodeFirstDatabaseSchema.pocotest](T1.pocotest_Id, T1.pocotest_f1, T1.pocotest_f2, T1.pocotest_f2a, T1.pocotest_f3, T1.pocotest_f5, T1.pocotest_f6b)
FROM (
    SELECT 
        T.Id AS pocotest_Id, 
        T.f1 AS pocotest_f1, 
        T.f2 AS pocotest_f2, 
        T.f2a AS pocotest_f2a, 
        T.f3 AS pocotest_f3, 
        T.f5 AS pocotest_f5, 
        T.f6b AS pocotest_f6b, 
        True AS _from0
    FROM Ef6Ctx3.poco1s AS T
) AS T1");
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM