如何实体框架pre-编译的观点得到加载实体、框架、加载、观点

由网友(月光下的独舞)分享简介:我发现我可以增加$ P $使用 EdmGen.exe 工具对编译我的观点我的应用程序的性能。I've discovered I can increase performance of my application by pre-compiling my views using the EdmGen.exe tool....

我发现我可以增加$ P $使用 EdmGen.exe 工具对编译我的观点我的应用程序的性能。

I've discovered I can increase performance of my application by pre-compiling my views using the EdmGen.exe tool.

这是一切都很好,但是没有我或我的大学能制定出如何生成的cs文件是实际使用的项目。 有不似乎是被产生的任何地方类的任何引用,所以它是如何得到包含?

This is all well and good, but neither me or my colleges can work out how the generated .cs file is actually used by the project. There doesnt seem to be any references to the class that was generated anywhere, so how is it getting included?

任何人都可以摆脱任何光线就以此为真的相当令人沮丧,不知道它是如何工作!

Can anyone shed any light on this as its really rather frustrating not knowing how it works!

我们已经经查实 EntityViewGenerationAttribute 是用来标记类类型为pre-编译的观点,但是这必然意味着其加载的,虽然反映。 如果多数民众赞成的情况下,有没有办法明确把它在code,一个pre-编译视图类应该用于某种看法?

We've acertained that the EntityViewGenerationAttribute is used to mark the class type for the pre-compiled view, however this must mean its loaded though reflection. If thats the case, is there any way of explicitly putting it in code that a pre-compiled view class should be used for a certain view?

推荐答案

您可以尝试改变产生code。使得不同的视图返回。 但是,如果你不返回一个观点我预计,英孚将失败。

You could try changing the generated code. So that a DIFFERENT view was returned. But if you dont return a view I expect that EF will fail.

的想法是,生成的类是对所有套组中的DbContext。事实上,如果认为犯规匹配的情况下,你有(哈希比较),你会得到一个运行时错误。

The idea is that the generated class is for ALL sets in a DBContext. And indeed if the view doesnt match the context you have (hash comparison) you will get a runtime error.

例如

   /// <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");
    }
阅读全文

相关推荐

最新文章