gpt4 book ai didi

c# - 在哪里放置 Entity Framework 6.0 预生成的 View

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:35 25 4
gpt4 key购买 nike

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

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

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

我的 Entity Framework edmx 文件位于“MyApp.DataAccess”项目中。我不知道将预生成的 View 文件放在哪里,无论是在“MyApp.DataAccess”类库中还是在“MyApp.GUI”windows 窗体项目中。目前预生成的 View 文件在“MyApp.DataAccess”类库中。

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

//------------------------------------------------------------------------------
// <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 的评论,我在每个预生成的 View 文件中都设置了断点。 DataAccess 类库中预生成的 View 被断点击中。因此,通常可以假设将预先生成的 View 文件放在edmx文件所在的DataAccess类库中(在我的这种情况下)。

关于c# - 在哪里放置 Entity Framework 6.0 预生成的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26517137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com