繁体   English   中英

实体框架6.0预生成视图的放置位置

[英]Where to place Entity Framework 6.0 pre-generated view

我正在使用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");
    }
}

}

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

根据Maarten的评论,我已经在每个预先生成的视图文件中放置了断点。 断点会命中DataAccess类库中的预生成视图。 因此,通常可以假定将预先生成的视图文件放在edmx文件所在的DataAccess类库中(在我的情况下)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM