在哪里放置Entity Framework 6.0预生成视图

时间:2014-10-22 21:07:53

标签: c# entity-framework dll

我正在使用Entity Framework 6.0开发Window Forms项目。我应用数据库优先方法并使用Visual Studio向导创建edmx文件。像所有其他人一样,我也生成预先生成的视图以提高性能。我用了Entity Framework Power Tools。它可以工作并生成my_EF.views.cs文件。

但我的第一个查询仍然需要很长时间

我怀疑我的项目文件结构可能是问题所在。在我的解决方案资源管理器中,我有两个项目“ MyApp.GUI ”(Windows窗体项目)和“ MyApp.DataAccess ”(类库项目)。我将“MyApp.DataAccess”的引用 dll 添加到“MyApp.GUI”。

我的实体框架 edmx 文件位于“ MyApp.DataAccess ”项目中。我不知道在“ MyApp.DataAccess ”类库或“ MyApp.GUI ”windows窗体项目中放置预生成的视图文件的位置。目前,预生成的视图文件位于“ MyApp.DataAccess ”类库中。

我的问题与我的项目文件结构有关吗?或者,可能是预生成的视图文件不起作用(由Entity Framework Power Tools生成)?这是我预先生成的视图文件。请建议我可能的解决方案。

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Data.Entity.Infrastructure.MappingViews;

[assembly: DbMappingViewCacheTypeAttribute(
    typeof(TheWayPointOfSale.DataAccess.TheWayPOSEntities),
    typeof(Edm_EntityMappingGeneratedViews.ViewsForBaseEntitySetsa6f884d523752b7a79e1bab1a97ba058ffdac6b45a04cc850e30f503a4e1fc49))]

namespace Edm_EntityMappingGeneratedViews
{
    using System;
    using System.CodeDom.Compiler;
    using System.Data.Entity.Core.Metadata.Edm;

/// <summary>
/// Implements a mapping view cache.
/// </summary>
[GeneratedCode("Entity Framework Power Tools", "0.9.0.0")]
internal sealed class ViewsForBaseEntitySetsa6f884d523752b7a79e1bab1a97ba058ffdac6b45a04cc850e30f503a4e1fc49 : DbMappingViewCache
{
    /// <summary>
    /// Gets a hash value computed over the mapping closure.
    /// </summary>
    public override string MappingHashValue
    {
        get { return "a6f884d523752b7a79e1bab1a97ba058ffdac6b45a04cc850e30f503a4e1fc49"; }
    }

    /// <summary>
    /// Gets a view corresponding to the specified extent.
    /// </summary>
    /// <param name="extent">The extent.</param>
    /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns>
    public override DbMappingView GetView(EntitySetBase extent)
    {
        if (extent == null)
        {
            throw new ArgumentNullException("extent");
        }

        var extentName = extent.EntityContainer.Name + "." + extent.Name;

        if (extentName == "TheWayPOSModelStoreContainer.Products")
        {
            return GetView0();
        }

        if (extentName == "TheWayPOSModelStoreContainer.Um")
        {
            return GetView1();
        }

        if (extentName == "TheWayPOSModelStoreContainer.Products_Um")
        {
            return GetView2();
        }

        if (extentName == "TheWayPOSEntities.Products")
        {
            return GetView3();
        }

        if (extentName == "TheWayPOSEntities.Ums")
        {
            return GetView4();
        }

        if (extentName == "TheWayPOSEntities.Products_Um")
        {
            return GetView5();
        }

        return null;
    }

    /// <summary>
    /// Gets the view for TheWayPOSModelStoreContainer.Products.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView0()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Products
    [TheWayPOSModel.Store.Products](T1.[Products.product_code], T1.[Products.product_name], T1.[Products.buying_price], T1.[Products.discount_percentage], T1.[Products.retail_price], T1.[Products.wholesale_price], T1.Products_supplier, T1.[Products.created_at], T1.[Products.updated_at])
FROM (
    SELECT 
        T.product_code AS [Products.product_code], 
        T.product_name AS [Products.product_name], 
        T.buying_price AS [Products.buying_price], 
        T.discount_percentage AS [Products.discount_percentage], 
        T.retail_price AS [Products.retail_price], 
        T.wholesale_price AS [Products.wholesale_price], 
        T.supplier AS Products_supplier, 
        T.created_at AS [Products.created_at], 
        T.updated_at AS [Products.updated_at], 
        True AS _from0
    FROM TheWayPOSEntities.Products AS T
) AS T1");
    }

    /// <summary>
    /// Gets the view for TheWayPOSModelStoreContainer.Um.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView1()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Um
    [TheWayPOSModel.Store.Um](T1.[Um.um_code], T1.[Um.um_shortname], T1.[Um.um_fullname], T1.Um_disposable, T1.[Um.disposed_um_code], T1.[Um.disposed_um_qty], T1.[Um.depend_on_product], T1.[Um.created_at], T1.[Um.updated_at])
FROM (
    SELECT 
        T.um_code AS [Um.um_code], 
        T.um_shortname AS [Um.um_shortname], 
        T.um_fullname AS [Um.um_fullname], 
        T.disposable AS Um_disposable, 
        T.disposed_um_code AS [Um.disposed_um_code], 
        T.disposed_um_qty AS [Um.disposed_um_qty], 
        T.depend_on_product AS [Um.depend_on_product], 
        T.created_at AS [Um.created_at], 
        T.updated_at AS [Um.updated_at], 
        True AS _from0
    FROM TheWayPOSEntities.Ums AS T
) AS T1");
    }

    /// <summary>
    /// Gets the view for TheWayPOSModelStoreContainer.Products_Um.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView2()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Products_Um
    [TheWayPOSModel.Store.Products_Um](T1.[Products_Um.id], T1.[Products_Um.product_code], T1.[Products_Um.um_code], T1.[Products_Um.disposed_um_code], T1.[Products_Um.disposed_um_qty])
FROM (
    SELECT 
        T.id AS [Products_Um.id], 
        T.product_code AS [Products_Um.product_code], 
        T.um_code AS [Products_Um.um_code], 
        T.disposed_um_code AS [Products_Um.disposed_um_code], 
        T.disposed_um_qty AS [Products_Um.disposed_um_qty], 
        True AS _from0
    FROM TheWayPOSEntities.Products_Um AS T
) AS T1");
    }

    /// <summary>
    /// Gets the view for TheWayPOSEntities.Products.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView3()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Products
    [TheWayPOSModel.Product](T1.[Product.product_code], T1.[Product.product_name], T1.[Product.buying_price], T1.[Product.discount_percentage], T1.[Product.retail_price], T1.[Product.wholesale_price], T1.Product_supplier, T1.[Product.created_at], T1.[Product.updated_at])
FROM (
    SELECT 
        T.product_code AS [Product.product_code], 
        T.product_name AS [Product.product_name], 
        T.buying_price AS [Product.buying_price], 
        T.discount_percentage AS [Product.discount_percentage], 
        T.retail_price AS [Product.retail_price], 
        T.wholesale_price AS [Product.wholesale_price], 
        T.supplier AS Product_supplier, 
        T.created_at AS [Product.created_at], 
        T.updated_at AS [Product.updated_at], 
        True AS _from0
    FROM TheWayPOSModelStoreContainer.Products AS T
) AS T1");
    }

    /// <summary>
    /// Gets the view for TheWayPOSEntities.Ums.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView4()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Ums
    [TheWayPOSModel.Um](T1.[Um.um_code], T1.[Um.um_shortname], T1.[Um.um_fullname], T1.Um_disposable, T1.[Um.disposed_um_code], T1.[Um.disposed_um_qty], T1.[Um.depend_on_product], T1.[Um.created_at], T1.[Um.updated_at])
FROM (
    SELECT 
        T.um_code AS [Um.um_code], 
        T.um_shortname AS [Um.um_shortname], 
        T.um_fullname AS [Um.um_fullname], 
        T.disposable AS Um_disposable, 
        T.disposed_um_code AS [Um.disposed_um_code], 
        T.disposed_um_qty AS [Um.disposed_um_qty], 
        T.depend_on_product AS [Um.depend_on_product], 
        T.created_at AS [Um.created_at], 
        T.updated_at AS [Um.updated_at], 
        True AS _from0
    FROM TheWayPOSModelStoreContainer.Um AS T
) AS T1");
    }

    /// <summary>
    /// Gets the view for TheWayPOSEntities.Products_Um.
    /// </summary>
    /// <returns>The mapping view.</returns>
    private static DbMappingView GetView5()
    {
        return new DbMappingView(@"
SELECT VALUE -- Constructing Products_Um
    [TheWayPOSModel.Products_Um](T1.[Products_Um.id], T1.[Products_Um.product_code], T1.[Products_Um.um_code], T1.[Products_Um.disposed_um_code], T1.[Products_Um.disposed_um_qty])
FROM (
    SELECT 
        T.id AS [Products_Um.id], 
        T.product_code AS [Products_Um.product_code], 
        T.um_code AS [Products_Um.um_code], 
        T.disposed_um_code AS [Products_Um.disposed_um_code], 
        T.disposed_um_qty AS [Products_Um.disposed_um_qty], 
        True AS _from0
    FROM TheWayPOSModelStoreContainer.Products_Um AS T
) AS T1");
    }
}

}

1 个答案:

答案 0 :(得分:0)

我知道这些信息不值得回答。但对于像我这样的其他新手,我想分享一下我的经历。

根据Maarten的评论,我在每个预先生成的视图文件中都添加了断点。 DataAccess 类库中的预生成视图被断点命中。因此,通常可以假设将预生成的视图文件放在edmx文件所在的 DataAccess 类库中(在我的各种情况下)。