0

使用 EF5.0 并查看编译,我可以看到一切正常。我从调用堆栈中看到视图被调用。edmx 属性元数据工件处理设置为 embed in assembly

下面的这个方法(构造函数)被调用。但它是怎么知道这个名字的?我可以在 1 个组件中拥有多个模型吗?我很高兴它有效,但我想知道下面发生了什么。

有任何想法吗?

public ViewsForBaseEntitySetsFE35229A04DD6E5585E40F6CE4FBC33EE6C9199EBD58235921B21B951250FF67()
    {
        this.EdmEntityContainerName = "BosMasterEntities";
        this.StoreEntityContainerName = "BosMasterModelStoreContainer";
        this.HashOverMappingClosure = "0edb68dd82ba8436bcabb10d30d018482670a8944e1013c90d795d35afea1b8d";
        this.HashOverAllExtentViews = "d0d326d5289ea43aa6ea7854e053ba0bd410789e3196101e38bace646c0fa404";
        this.ViewCount = 34;
    }
4

1 回答 1

4

实际上,您在截断的代码中遗漏了两条重要信息 - 代码看起来更像这样:

[assembly: System.Data.Mapping.EntityViewGenerationAttribute(typeof(Edm_EntityMappingGeneratedViews.ViewsForBaseEntitySets6EB2ED815B2C1EA5C534EACE1F3EA695AAF84C0704F820B6C583CE86EFE39C0A))]

namespace Edm_EntityMappingGeneratedViews
{    
    public sealed class ViewsForBaseEntitySets6EB2ED815B2C1EA5C534EACE1F3EA695AAF84C0704F820B6C583CE86EFE39C0A : System.Data.Mapping.EntityViewContainer
    {

        /// <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 ViewsForBaseEntitySets6EB2ED815B2C1EA5C534EACE1F3EA695AAF84C0704F820B6C583CE86EFE39C0A()
        {
            this.EdmEntityContainerName = "Context";
            this.StoreEntityContainerName = "CodeFirstDatabase";
            this.HashOverMappingClosure = "565d1a0ab9083c0e3d54e4d636e9ea8ace70a69f415e728c42b1e687acf65932";
            this.HashOverAllExtentViews = "84db96d2d3c40ffdbcbf3ab1e49f50e068df40cd9e62f87416402f6eb3569da0";
            this.ViewCount = 2;
        }
        ...

首先,有一个 EntityViewGenerationAttribute 类型的程序集级属性。只有具有此属性的程序集才会被视为可以包含视图的程序集。如果您仔细查看该属性,您会发现该属性具有包含视图的类的类型。您可以在一个程序集中拥有多个 EntityViewGenerationAttribute。其次,包含视图的类是从 EntityViewContainer 派生的。如果 EntityViewGenerationAttribute 中指定的类型不是从 EntityViewContainer 派生的,则 EF 将抛出。

于 2012-10-02T21:56:40.467 回答