EntityFramework性能之预生成视图

前面提到过这个网址:性能注意事项(实体框架) https://msdn.microsoft.com/zh-cn/library/cc853327.aspx
注意版本: .NET Framework (current version) (还有一个其他版本, .NET Framework 4).

此文提到 查询执行的各个阶段[格式:操作(相对成本)]:
加载元数据(中等),打开数据库连接(中等),生成视图(高),准备查询(中等),执行查询(低),加载和验证类型(低),跟踪(低),是对象具体化(中等)

还是截个图吧.

其中,我特别在意‘生成视图‘这个阶段,高成本(其它阶段要么频率低要么成本低).
生成视图,注释如下:在实体框架可以针对概念模型执行查询或将更改保存到数据源之前,它必须生成一组本地查询视图才能访问数据库。 由于生成这些视图会产生很高的成本,因此,您可以在设计时预生成视图并将它们添加到项目。 有关详细信息,请参阅How to: Pre-Generate Views to Improve Query Performance。

于是,我就去看How to: Pre-Generate Views to Improve Query Performance(以下简称H文)。(如何:预生成视图以提高查询性能)

动手,建立解决方案名EFTest,控制台名EFIce.
简要说下H文的步骤(跟H文有差异):
a.打开PhoneBookModel.edmx,在模型浏览器里,找到PhoneBookModel,右键,属性,有一项属性名为‘元数据项目处理‘,默认值是‘嵌入输出程序集中‘,更改为‘复制到输出目录‘;
b.生成PhoneBookModel.ssdl,PhoneBookModel.csdl,PhoneBookModel.msl,PhoneBookModel.Views.cs四个文件并加入到项目里,其中.ssdl,.csdl,.msl三个文件的属性生成操作设置为‘嵌入的资源‘,而PhoneBookModel.Views.cs文件会直接编译到.dll里.
此处生成文件的方法:命令提示符执行
C:\Users\Administrator>EdmGen /mode:FullGeneration /connectionstring:"server=.;user id=sa;password=******;persist security info=True;database=PhoneBook" /provider:"System.Data.SqlClient" /outssdl:PhoneBookModel.ssdl /outcsdl:PhoneBookModel.csdl /outmsl:PhoneBookModel.msl /outobjectlayer:PhoneBookObject.cs /outviews:PhoneBook.Views.cs /namespace:"EFIce" /entitycontainer:"PhoneBookEntitiesContainer

产生的文件的位置C:\Users\Administrator目录下.

PhoneBookModel.edmx的图解:

文件结果:

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.36282
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

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

namespace Edm_EntityMappingGeneratedViews
{

    /// <Summary>
    /// 此类型包含在设计时生成的 EntitySets 和 AssociationSets 的视图。
    /// </Summary>
    public sealed class ViewsForBaseEntitySets9E94E67D0053D8FDE07EEEB8F52E0E47D0A29AB22FB0BCB5EB6BE8BC009D5748 : System.Data.Mapping.EntityViewContainer
    {

        /// <Summary>
        /// 构造函数存储各区的视图,以及根据元数据和映射结束和视图生成的哈希值。
        /// </Summary>
        public ViewsForBaseEntitySets9E94E67D0053D8FDE07EEEB8F52E0E47D0A29AB22FB0BCB5EB6BE8BC009D5748()
        {
            this.EdmEntityContainerName = "PhoneBookEntitiesContainer";
            this.StoreEntityContainerName = "EFIceStoreContainer";
            this.HashOverMappingClosure = "4c6b0bf3e3884e8b4a6c4c7c60d99b787ec990e9b24297519ab203951cadc07d";
            this.HashOverAllExtentViews = "d048405239ad31569ab8a2a9f67381c39d4130d40b625903b35e1e8d2d1266f5";
            this.ViewCount = 8;
        }

        /// <Summary>
        /// 此方法返回给定索引的视图。
        /// </Summary>
        protected override System.Collections.Generic.KeyValuePair<string, string> GetViewAt(int index)
        {
            if ((index == 0))
            {
                return GetView0();
            }
            if ((index == 1))
            {
                return GetView1();
            }
            if ((index == 2))
            {
                return GetView2();
            }
            if ((index == 3))
            {
                return GetView3();
            }
            if ((index == 4))
            {
                return GetView4();
            }
            if ((index == 5))
            {
                return GetView5();
            }
            if ((index == 6))
            {
                return GetView6();
            }
            if ((index == 7))
            {
                return GetView7();
            }
            throw new System.IndexOutOfRangeException();
        }

        /// <Summary>
        /// 返回 EFIceStoreContainer.AccountInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView0()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("EFIceStoreContainer.AccountInfo", @"
    SELECT VALUE -- Constructing AccountInfo
        [EFIce.Store.AccountInfo](T1.AccountInfo_ID, T1.AccountInfo_Account, T1.AccountInfo_AccountName, T1.AccountInfo_Pwd)
    FROM (
        SELECT
            T.ID AS AccountInfo_ID,
            T.Account AS AccountInfo_Account,
            T.AccountName AS AccountInfo_AccountName,
            T.Pwd AS AccountInfo_Pwd,
            True AS _from0
        FROM PhoneBookEntitiesContainer.AccountInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 PhoneBookEntitiesContainer.AccountInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView1()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("PhoneBookEntitiesContainer.AccountInfo", @"
    SELECT VALUE -- Constructing AccountInfo
        [EFIce.AccountInfo](T1.AccountInfo_ID, T1.AccountInfo_Account, T1.AccountInfo_AccountName, T1.AccountInfo_Pwd)
    FROM (
        SELECT
            T.ID AS AccountInfo_ID,
            T.Account AS AccountInfo_Account,
            T.AccountName AS AccountInfo_AccountName,
            T.Pwd AS AccountInfo_Pwd,
            True AS _from0
        FROM EFIceStoreContainer.AccountInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 EFIceStoreContainer.ContactInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView2()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("EFIceStoreContainer.ContactInfo", @"
    SELECT VALUE -- Constructing ContactInfo
        [EFIce.Store.ContactInfo](T1.ContactInfo_ID, T1.ContactInfo_ContactId, T1.ContactInfo_IsDelete, T1.ContactInfo_Account, T1.ContactInfo_ContactName, T1.ContactInfo_CommonMobile, T1.ContactInfo_HeadPortrait, T1.ContactInfo_AttFile, T1.ContactInfo_GroupId)
    FROM (
        SELECT
            T.ID AS ContactInfo_ID,
            T.ContactId AS ContactInfo_ContactId,
            T.IsDelete AS ContactInfo_IsDelete,
            T.Account AS ContactInfo_Account,
            T.ContactName AS ContactInfo_ContactName,
            T.CommonMobile AS ContactInfo_CommonMobile,
            T.HeadPortrait AS ContactInfo_HeadPortrait,
            T.AttFile AS ContactInfo_AttFile,
            T.GroupId AS ContactInfo_GroupId,
            True AS _from0
        FROM PhoneBookEntitiesContainer.ContactInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 EFIceStoreContainer.GroupInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView3()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("EFIceStoreContainer.GroupInfo", @"
    SELECT VALUE -- Constructing GroupInfo
        [EFIce.Store.GroupInfo](T1.GroupInfo_GroupId, T1.GroupInfo_GroupName)
    FROM (
        SELECT
            T.GroupId AS GroupInfo_GroupId,
            T.GroupName AS GroupInfo_GroupName,
            True AS _from0
        FROM PhoneBookEntitiesContainer.GroupInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 PhoneBookEntitiesContainer.ContactInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView4()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("PhoneBookEntitiesContainer.ContactInfo", @"
    SELECT VALUE -- Constructing ContactInfo
        [EFIce.ContactInfo](T1.ContactInfo_ID, T1.ContactInfo_ContactId, T1.ContactInfo_IsDelete, T1.ContactInfo_Account, T1.ContactInfo_ContactName, T1.ContactInfo_CommonMobile, T1.ContactInfo_HeadPortrait, T1.ContactInfo_AttFile, T1.ContactInfo_GroupId)
    FROM (
        SELECT
            T.ID AS ContactInfo_ID,
            T.ContactId AS ContactInfo_ContactId,
            T.IsDelete AS ContactInfo_IsDelete,
            T.Account AS ContactInfo_Account,
            T.ContactName AS ContactInfo_ContactName,
            T.CommonMobile AS ContactInfo_CommonMobile,
            T.HeadPortrait AS ContactInfo_HeadPortrait,
            T.AttFile AS ContactInfo_AttFile,
            T.GroupId AS ContactInfo_GroupId,
            True AS _from0
        FROM EFIceStoreContainer.ContactInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 PhoneBookEntitiesContainer.GroupInfo 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView5()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("PhoneBookEntitiesContainer.GroupInfo", @"
    SELECT VALUE -- Constructing GroupInfo
        [EFIce.GroupInfo](T1.GroupInfo_GroupId, T1.GroupInfo_GroupName)
    FROM (
        SELECT
            T.GroupId AS GroupInfo_GroupId,
            T.GroupName AS GroupInfo_GroupName,
            True AS _from0
        FROM EFIceStoreContainer.GroupInfo AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 EFIceStoreContainer.ContactInGroup 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView6()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("EFIceStoreContainer.ContactInGroup", @"
    SELECT VALUE -- Constructing ContactInGroup
        [EFIce.Store.ContactInGroup](T1.ContactInGroup_Id, T1.ContactInGroup_Account, T1.ContactInGroup_GroupNumber, T1.ContactInGroup_ContactId, T1.ContactInGroup_IsDelete, T1.ContactInGroup_UpdateTime)
    FROM (
        SELECT
            T.Id AS ContactInGroup_Id,
            T.Account AS ContactInGroup_Account,
            T.GroupNumber AS ContactInGroup_GroupNumber,
            T.ContactId AS ContactInGroup_ContactId,
            T.IsDelete AS ContactInGroup_IsDelete,
            T.UpdateTime AS ContactInGroup_UpdateTime,
            True AS _from0
        FROM PhoneBookEntitiesContainer.ContactInGroup AS T
    ) AS T1");
        }

        /// <Summary>
        /// 返回 PhoneBookEntitiesContainer.ContactInGroup 的视图
        /// </Summary>
        private System.Collections.Generic.KeyValuePair<string, string> GetView7()
        {
            return new System.Collections.Generic.KeyValuePair<string, string>("PhoneBookEntitiesContainer.ContactInGroup", @"
    SELECT VALUE -- Constructing ContactInGroup
        [EFIce.ContactInGroup](T1.ContactInGroup_Id, T1.ContactInGroup_Account, T1.ContactInGroup_GroupNumber, T1.ContactInGroup_ContactId, T1.ContactInGroup_IsDelete, T1.ContactInGroup_UpdateTime)
    FROM (
        SELECT
            T.Id AS ContactInGroup_Id,
            T.Account AS ContactInGroup_Account,
            T.GroupNumber AS ContactInGroup_GroupNumber,
            T.ContactId AS ContactInGroup_ContactId,
            T.IsDelete AS ContactInGroup_IsDelete,
            T.UpdateTime AS ContactInGroup_UpdateTime,
            True AS _from0
        FROM EFIceStoreContainer.ContactInGroup AS T
    ) AS T1");
        }
    }
}

PhoneBook.Views.cs

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="EFIce" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
  <EntityContainer Name="PhoneBookEntitiesContainer" annotation:LazyLoadingEnabled="true">
    <EntitySet Name="AccountInfo" EntityType="EFIce.AccountInfo" />
    <EntitySet Name="ContactInfo" EntityType="EFIce.ContactInfo" />
    <EntitySet Name="ContactInGroup" EntityType="EFIce.ContactInGroup" />
    <EntitySet Name="GroupInfo" EntityType="EFIce.GroupInfo" />
    <AssociationSet Name="FK_ContactInfo_GroupInfo" Association="EFIce.FK_ContactInfo_GroupInfo">
      <End Role="GroupInfo" EntitySet="GroupInfo" />
      <End Role="ContactInfo" EntitySet="ContactInfo" />
    </AssociationSet>
  </EntityContainer>
  <EntityType Name="AccountInfo">
    <Key>
      <PropertyRef Name="ID" />
    </Key>
    <Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
    <Property Name="Account" Type="String" MaxLength="64" Unicode="true" FixedLength="false" />
    <Property Name="AccountName" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
    <Property Name="Pwd" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
  </EntityType>
  <EntityType Name="ContactInfo">
    <Key>
      <PropertyRef Name="ID" />
    </Key>
    <Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
    <Property Name="ContactId" Type="String" Nullable="false" MaxLength="128" Unicode="true" FixedLength="false" />
    <Property Name="IsDelete" Type="Int32" Nullable="false" />
    <Property Name="Account" Type="String" Nullable="false" MaxLength="64" Unicode="true" FixedLength="false" />
    <Property Name="ContactName" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
    <Property Name="CommonMobile" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
    <Property Name="HeadPortrait" Type="String" MaxLength="256" Unicode="true" FixedLength="false" />
    <Property Name="AttFile" Type="String" MaxLength="256" Unicode="true" FixedLength="false" />
    <Property Name="GroupId" Type="Int32" />
    <NavigationProperty Name="GroupInfo" Relationship="EFIce.FK_ContactInfo_GroupInfo" FromRole="ContactInfo" ToRole="GroupInfo" />
  </EntityType>
  <EntityType Name="ContactInGroup">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="String" Nullable="false" MaxLength="128" Unicode="false" FixedLength="false" />
    <Property Name="Account" Type="String" Nullable="false" MaxLength="64" Unicode="true" FixedLength="false" />
    <Property Name="GroupNumber" Type="String" Nullable="false" MaxLength="16" Unicode="true" FixedLength="false" />
    <Property Name="ContactId" Type="String" Nullable="false" MaxLength="128" Unicode="false" FixedLength="false" />
    <Property Name="IsDelete" Type="Int32" />
    <Property Name="UpdateTime" Type="DateTime" />
  </EntityType>
  <EntityType Name="GroupInfo">
    <Key>
      <PropertyRef Name="GroupId" />
    </Key>
    <Property Name="GroupId" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
    <Property Name="GroupName" Type="String" Nullable="false" MaxLength="300" Unicode="true" FixedLength="false" />
    <NavigationProperty Name="ContactInfo" Relationship="EFIce.FK_ContactInfo_GroupInfo" FromRole="GroupInfo" ToRole="ContactInfo" />
  </EntityType>
  <Association Name="FK_ContactInfo_GroupInfo">
    <End Role="GroupInfo" Type="EFIce.GroupInfo" Multiplicity="0..1" />
    <End Role="ContactInfo" Type="EFIce.ContactInfo" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="GroupInfo">
        <PropertyRef Name="GroupId" />
      </Principal>
      <Dependent Role="ContactInfo">
        <PropertyRef Name="GroupId" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
</Schema>

PhoneBookModel.csdl

<?xml version="1.0" encoding="utf-8"?>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
  <EntityContainerMapping StorageEntityContainer="EFIceStoreContainer" CdmEntityContainer="PhoneBookEntitiesContainer">
    <EntitySetMapping Name="AccountInfo">
      <EntityTypeMapping TypeName="EFIce.AccountInfo">
        <MappingFragment StoreEntitySet="AccountInfo">
          <ScalarProperty Name="ID" ColumnName="ID" />
          <ScalarProperty Name="Account" ColumnName="Account" />
          <ScalarProperty Name="AccountName" ColumnName="AccountName" />
          <ScalarProperty Name="Pwd" ColumnName="Pwd" />
        </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>
    <EntitySetMapping Name="ContactInfo">
      <EntityTypeMapping TypeName="EFIce.ContactInfo">
        <MappingFragment StoreEntitySet="ContactInfo">
          <ScalarProperty Name="ID" ColumnName="ID" />
          <ScalarProperty Name="ContactId" ColumnName="ContactId" />
          <ScalarProperty Name="IsDelete" ColumnName="IsDelete" />
          <ScalarProperty Name="Account" ColumnName="Account" />
          <ScalarProperty Name="ContactName" ColumnName="ContactName" />
          <ScalarProperty Name="CommonMobile" ColumnName="CommonMobile" />
          <ScalarProperty Name="HeadPortrait" ColumnName="HeadPortrait" />
          <ScalarProperty Name="AttFile" ColumnName="AttFile" />
          <ScalarProperty Name="GroupId" ColumnName="GroupId" />
        </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>
    <EntitySetMapping Name="ContactInGroup">
      <EntityTypeMapping TypeName="EFIce.ContactInGroup">
        <MappingFragment StoreEntitySet="ContactInGroup">
          <ScalarProperty Name="Id" ColumnName="Id" />
          <ScalarProperty Name="Account" ColumnName="Account" />
          <ScalarProperty Name="GroupNumber" ColumnName="GroupNumber" />
          <ScalarProperty Name="ContactId" ColumnName="ContactId" />
          <ScalarProperty Name="IsDelete" ColumnName="IsDelete" />
          <ScalarProperty Name="UpdateTime" ColumnName="UpdateTime" />
        </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>
    <EntitySetMapping Name="GroupInfo">
      <EntityTypeMapping TypeName="EFIce.GroupInfo">
        <MappingFragment StoreEntitySet="GroupInfo">
          <ScalarProperty Name="GroupId" ColumnName="GroupId" />
          <ScalarProperty Name="GroupName" ColumnName="GroupName" />
        </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>
  </EntityContainerMapping>
</Mapping>

PhoneBookModel.msl

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="EFIce.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
  <EntityContainer Name="EFIceStoreContainer">
    <EntitySet Name="AccountInfo" EntityType="EFIce.Store.AccountInfo" store:Type="Tables" Schema="dbo" />
    <EntitySet Name="ContactInfo" EntityType="EFIce.Store.ContactInfo" store:Type="Tables" Schema="dbo" />
    <EntitySet Name="ContactInGroup" EntityType="EFIce.Store.ContactInGroup" store:Type="Tables" Schema="dbo" />
    <EntitySet Name="GroupInfo" EntityType="EFIce.Store.GroupInfo" store:Type="Tables" Schema="dbo" />
    <AssociationSet Name="FK_ContactInfo_GroupInfo" Association="EFIce.Store.FK_ContactInfo_GroupInfo">
      <End Role="GroupInfo" EntitySet="GroupInfo" />
      <End Role="ContactInfo" EntitySet="ContactInfo" />
    </AssociationSet>
  </EntityContainer>
  <EntityType Name="AccountInfo">
    <Key>
      <PropertyRef Name="ID" />
    </Key>
    <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="Account" Type="nvarchar" MaxLength="64" />
    <Property Name="AccountName" Type="nvarchar" MaxLength="50" />
    <Property Name="Pwd" Type="nvarchar" MaxLength="50" />
  </EntityType>
  <EntityType Name="ContactInfo">
    <Key>
      <PropertyRef Name="ID" />
    </Key>
    <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="ContactId" Type="nvarchar" Nullable="false" MaxLength="128" />
    <Property Name="IsDelete" Type="int" Nullable="false" />
    <Property Name="Account" Type="nvarchar" Nullable="false" MaxLength="64" />
    <Property Name="ContactName" Type="nvarchar" Nullable="false" MaxLength="50" />
    <Property Name="CommonMobile" Type="nvarchar" MaxLength="50" />
    <Property Name="HeadPortrait" Type="nvarchar" MaxLength="256" />
    <Property Name="AttFile" Type="nvarchar" MaxLength="256" />
    <Property Name="GroupId" Type="int" />
  </EntityType>
  <EntityType Name="ContactInGroup">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="varchar" Nullable="false" MaxLength="128" />
    <Property Name="Account" Type="nvarchar" Nullable="false" MaxLength="64" />
    <Property Name="GroupNumber" Type="nvarchar" Nullable="false" MaxLength="16" />
    <Property Name="ContactId" Type="varchar" Nullable="false" MaxLength="128" />
    <Property Name="IsDelete" Type="int" />
    <Property Name="UpdateTime" Type="datetime" />
  </EntityType>
  <EntityType Name="GroupInfo">
    <Key>
      <PropertyRef Name="GroupId" />
    </Key>
    <Property Name="GroupId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="GroupName" Type="nvarchar" Nullable="false" MaxLength="300" />
  </EntityType>
  <Association Name="FK_ContactInfo_GroupInfo">
    <End Role="GroupInfo" Type="EFIce.Store.GroupInfo" Multiplicity="0..1" />
    <End Role="ContactInfo" Type="EFIce.Store.ContactInfo" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="GroupInfo">
        <PropertyRef Name="GroupId" />
      </Principal>
      <Dependent Role="ContactInfo">
        <PropertyRef Name="GroupId" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
</Schema>

PhoneBookModel.ssdl

//------------------------------------------------------------------------------
// <auto-generated>
//    此代码是根据模板生成的。
//
//    手动更改此文件可能会导致应用程序中发生异常行为。
//    如果重新生成代码,则将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
#region EDM 关系源元数据

[assembly: EdmRelationshipAttribute("EFIce", "FK_ContactInfo_GroupInfo", "GroupInfo", System.Data.Metadata.Edm.RelationshipMultiplicity.ZeroOrOne, typeof(EFIce.GroupInfo), "ContactInfo", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EFIce.ContactInfo), true)]

#endregion

namespace EFIce
{
    #region 上下文

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    public partial class PhoneBookEntitiesContainer : ObjectContext
    {
        #region 构造函数

        /// <summary>
        /// 请使用应用程序配置文件的“PhoneBookEntitiesContainer”部分中的连接字符串初始化新 PhoneBookEntitiesContainer 对象。
        /// </summary>
        public PhoneBookEntitiesContainer() : base("name=PhoneBookEntitiesContainer", "PhoneBookEntitiesContainer")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        /// <summary>
        /// 初始化新的 PhoneBookEntitiesContainer 对象。
        /// </summary>
        public PhoneBookEntitiesContainer(string connectionString) : base(connectionString, "PhoneBookEntitiesContainer")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        /// <summary>
        /// 初始化新的 PhoneBookEntitiesContainer 对象。
        /// </summary>
        public PhoneBookEntitiesContainer(EntityConnection connection) : base(connection, "PhoneBookEntitiesContainer")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        #endregion

        #region 分部方法

        partial void OnContextCreated();

        #endregion

        #region ObjectSet 属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        public ObjectSet<AccountInfo> AccountInfo
        {
            get
            {
                if ((_AccountInfo == null))
                {
                    _AccountInfo = base.CreateObjectSet<AccountInfo>("AccountInfo");
                }
                return _AccountInfo;
            }
        }
        private ObjectSet<AccountInfo> _AccountInfo;

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        public ObjectSet<ContactInfo> ContactInfo
        {
            get
            {
                if ((_ContactInfo == null))
                {
                    _ContactInfo = base.CreateObjectSet<ContactInfo>("ContactInfo");
                }
                return _ContactInfo;
            }
        }
        private ObjectSet<ContactInfo> _ContactInfo;

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        public ObjectSet<ContactInGroup> ContactInGroup
        {
            get
            {
                if ((_ContactInGroup == null))
                {
                    _ContactInGroup = base.CreateObjectSet<ContactInGroup>("ContactInGroup");
                }
                return _ContactInGroup;
            }
        }
        private ObjectSet<ContactInGroup> _ContactInGroup;

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        public ObjectSet<GroupInfo> GroupInfo
        {
            get
            {
                if ((_GroupInfo == null))
                {
                    _GroupInfo = base.CreateObjectSet<GroupInfo>("GroupInfo");
                }
                return _GroupInfo;
            }
        }
        private ObjectSet<GroupInfo> _GroupInfo;

        #endregion

        #region AddTo 方法

        /// <summary>
        /// 用于向 AccountInfo EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
        /// </summary>
        public void AddToAccountInfo(AccountInfo accountInfo)
        {
            base.AddObject("AccountInfo", accountInfo);
        }

        /// <summary>
        /// 用于向 ContactInfo EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
        /// </summary>
        public void AddToContactInfo(ContactInfo contactInfo)
        {
            base.AddObject("ContactInfo", contactInfo);
        }

        /// <summary>
        /// 用于向 ContactInGroup EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
        /// </summary>
        public void AddToContactInGroup(ContactInGroup contactInGroup)
        {
            base.AddObject("ContactInGroup", contactInGroup);
        }

        /// <summary>
        /// 用于向 GroupInfo EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
        /// </summary>
        public void AddToGroupInfo(GroupInfo groupInfo)
        {
            base.AddObject("GroupInfo", groupInfo);
        }

        #endregion

    }

    #endregion

    #region 实体

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="EFIce", Name="AccountInfo")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class AccountInfo : EntityObject
    {
        #region 工厂方法

        /// <summary>
        /// 创建新的 AccountInfo 对象。
        /// </summary>
        /// <param name="id">ID 属性的初始值。</param>
        public static AccountInfo CreateAccountInfo(global::System.Int32 id)
        {
            AccountInfo accountInfo = new AccountInfo();
            accountInfo.ID = id;
            return accountInfo;
        }

        #endregion

        #region 基元属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    OnIDChanging(value);
                    ReportPropertyChanging("ID");
                    _ID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ID");
                    OnIDChanged();
                }
            }
        }
        private global::System.Int32 _ID;
        partial void OnIDChanging(global::System.Int32 value);
        partial void OnIDChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Account
        {
            get
            {
                return _Account;
            }
            set
            {
                OnAccountChanging(value);
                ReportPropertyChanging("Account");
                _Account = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Account");
                OnAccountChanged();
            }
        }
        private global::System.String _Account;
        partial void OnAccountChanging(global::System.String value);
        partial void OnAccountChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String AccountName
        {
            get
            {
                return _AccountName;
            }
            set
            {
                OnAccountNameChanging(value);
                ReportPropertyChanging("AccountName");
                _AccountName = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("AccountName");
                OnAccountNameChanged();
            }
        }
        private global::System.String _AccountName;
        partial void OnAccountNameChanging(global::System.String value);
        partial void OnAccountNameChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Pwd
        {
            get
            {
                return _Pwd;
            }
            set
            {
                OnPwdChanging(value);
                ReportPropertyChanging("Pwd");
                _Pwd = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Pwd");
                OnPwdChanged();
            }
        }
        private global::System.String _Pwd;
        partial void OnPwdChanging(global::System.String value);
        partial void OnPwdChanged();

        #endregion

    }

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="EFIce", Name="ContactInfo")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class ContactInfo : EntityObject
    {
        #region 工厂方法

        /// <summary>
        /// 创建新的 ContactInfo 对象。
        /// </summary>
        /// <param name="id">ID 属性的初始值。</param>
        /// <param name="contactId">ContactId 属性的初始值。</param>
        /// <param name="isDelete">IsDelete 属性的初始值。</param>
        /// <param name="account">Account 属性的初始值。</param>
        /// <param name="contactName">ContactName 属性的初始值。</param>
        public static ContactInfo CreateContactInfo(global::System.Int32 id, global::System.String contactId, global::System.Int32 isDelete, global::System.String account, global::System.String contactName)
        {
            ContactInfo contactInfo = new ContactInfo();
            contactInfo.ID = id;
            contactInfo.ContactId = contactId;
            contactInfo.IsDelete = isDelete;
            contactInfo.Account = account;
            contactInfo.ContactName = contactName;
            return contactInfo;
        }

        #endregion

        #region 基元属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    OnIDChanging(value);
                    ReportPropertyChanging("ID");
                    _ID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ID");
                    OnIDChanged();
                }
            }
        }
        private global::System.Int32 _ID;
        partial void OnIDChanging(global::System.Int32 value);
        partial void OnIDChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ContactId
        {
            get
            {
                return _ContactId;
            }
            set
            {
                OnContactIdChanging(value);
                ReportPropertyChanging("ContactId");
                _ContactId = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ContactId");
                OnContactIdChanged();
            }
        }
        private global::System.String _ContactId;
        partial void OnContactIdChanging(global::System.String value);
        partial void OnContactIdChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 IsDelete
        {
            get
            {
                return _IsDelete;
            }
            set
            {
                OnIsDeleteChanging(value);
                ReportPropertyChanging("IsDelete");
                _IsDelete = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("IsDelete");
                OnIsDeleteChanged();
            }
        }
        private global::System.Int32 _IsDelete;
        partial void OnIsDeleteChanging(global::System.Int32 value);
        partial void OnIsDeleteChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Account
        {
            get
            {
                return _Account;
            }
            set
            {
                OnAccountChanging(value);
                ReportPropertyChanging("Account");
                _Account = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Account");
                OnAccountChanged();
            }
        }
        private global::System.String _Account;
        partial void OnAccountChanging(global::System.String value);
        partial void OnAccountChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ContactName
        {
            get
            {
                return _ContactName;
            }
            set
            {
                OnContactNameChanging(value);
                ReportPropertyChanging("ContactName");
                _ContactName = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ContactName");
                OnContactNameChanged();
            }
        }
        private global::System.String _ContactName;
        partial void OnContactNameChanging(global::System.String value);
        partial void OnContactNameChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String CommonMobile
        {
            get
            {
                return _CommonMobile;
            }
            set
            {
                OnCommonMobileChanging(value);
                ReportPropertyChanging("CommonMobile");
                _CommonMobile = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("CommonMobile");
                OnCommonMobileChanged();
            }
        }
        private global::System.String _CommonMobile;
        partial void OnCommonMobileChanging(global::System.String value);
        partial void OnCommonMobileChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String HeadPortrait
        {
            get
            {
                return _HeadPortrait;
            }
            set
            {
                OnHeadPortraitChanging(value);
                ReportPropertyChanging("HeadPortrait");
                _HeadPortrait = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("HeadPortrait");
                OnHeadPortraitChanged();
            }
        }
        private global::System.String _HeadPortrait;
        partial void OnHeadPortraitChanging(global::System.String value);
        partial void OnHeadPortraitChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String AttFile
        {
            get
            {
                return _AttFile;
            }
            set
            {
                OnAttFileChanging(value);
                ReportPropertyChanging("AttFile");
                _AttFile = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("AttFile");
                OnAttFileChanged();
            }
        }
        private global::System.String _AttFile;
        partial void OnAttFileChanging(global::System.String value);
        partial void OnAttFileChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> GroupId
        {
            get
            {
                return _GroupId;
            }
            set
            {
                OnGroupIdChanging(value);
                ReportPropertyChanging("GroupId");
                _GroupId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("GroupId");
                OnGroupIdChanged();
            }
        }
        private Nullable<global::System.Int32> _GroupId;
        partial void OnGroupIdChanging(Nullable<global::System.Int32> value);
        partial void OnGroupIdChanged();

        #endregion

        #region 导航属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("EFIce", "FK_ContactInfo_GroupInfo", "GroupInfo")]
        public GroupInfo GroupInfo
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<GroupInfo>("EFIce.FK_ContactInfo_GroupInfo", "GroupInfo").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<GroupInfo>("EFIce.FK_ContactInfo_GroupInfo", "GroupInfo").Value = value;
            }
        }
        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<GroupInfo> GroupInfoReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<GroupInfo>("EFIce.FK_ContactInfo_GroupInfo", "GroupInfo");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<GroupInfo>("EFIce.FK_ContactInfo_GroupInfo", "GroupInfo", value);
                }
            }
        }

        #endregion

    }

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="EFIce", Name="ContactInGroup")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class ContactInGroup : EntityObject
    {
        #region 工厂方法

        /// <summary>
        /// 创建新的 ContactInGroup 对象。
        /// </summary>
        /// <param name="id">Id 属性的初始值。</param>
        /// <param name="account">Account 属性的初始值。</param>
        /// <param name="groupNumber">GroupNumber 属性的初始值。</param>
        /// <param name="contactId">ContactId 属性的初始值。</param>
        public static ContactInGroup CreateContactInGroup(global::System.String id, global::System.String account, global::System.String groupNumber, global::System.String contactId)
        {
            ContactInGroup contactInGroup = new ContactInGroup();
            contactInGroup.Id = id;
            contactInGroup.Account = account;
            contactInGroup.GroupNumber = groupNumber;
            contactInGroup.ContactId = contactId;
            return contactInGroup;
        }

        #endregion

        #region 基元属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Id
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id != value)
                {
                    OnIdChanging(value);
                    ReportPropertyChanging("Id");
                    _Id = StructuralObject.SetValidValue(value, false);
                    ReportPropertyChanged("Id");
                    OnIdChanged();
                }
            }
        }
        private global::System.String _Id;
        partial void OnIdChanging(global::System.String value);
        partial void OnIdChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Account
        {
            get
            {
                return _Account;
            }
            set
            {
                OnAccountChanging(value);
                ReportPropertyChanging("Account");
                _Account = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Account");
                OnAccountChanged();
            }
        }
        private global::System.String _Account;
        partial void OnAccountChanging(global::System.String value);
        partial void OnAccountChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String GroupNumber
        {
            get
            {
                return _GroupNumber;
            }
            set
            {
                OnGroupNumberChanging(value);
                ReportPropertyChanging("GroupNumber");
                _GroupNumber = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("GroupNumber");
                OnGroupNumberChanged();
            }
        }
        private global::System.String _GroupNumber;
        partial void OnGroupNumberChanging(global::System.String value);
        partial void OnGroupNumberChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ContactId
        {
            get
            {
                return _ContactId;
            }
            set
            {
                OnContactIdChanging(value);
                ReportPropertyChanging("ContactId");
                _ContactId = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ContactId");
                OnContactIdChanged();
            }
        }
        private global::System.String _ContactId;
        partial void OnContactIdChanging(global::System.String value);
        partial void OnContactIdChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> IsDelete
        {
            get
            {
                return _IsDelete;
            }
            set
            {
                OnIsDeleteChanging(value);
                ReportPropertyChanging("IsDelete");
                _IsDelete = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("IsDelete");
                OnIsDeleteChanged();
            }
        }
        private Nullable<global::System.Int32> _IsDelete;
        partial void OnIsDeleteChanging(Nullable<global::System.Int32> value);
        partial void OnIsDeleteChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.DateTime> UpdateTime
        {
            get
            {
                return _UpdateTime;
            }
            set
            {
                OnUpdateTimeChanging(value);
                ReportPropertyChanging("UpdateTime");
                _UpdateTime = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("UpdateTime");
                OnUpdateTimeChanged();
            }
        }
        private Nullable<global::System.DateTime> _UpdateTime;
        partial void OnUpdateTimeChanging(Nullable<global::System.DateTime> value);
        partial void OnUpdateTimeChanged();

        #endregion

    }

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="EFIce", Name="GroupInfo")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class GroupInfo : EntityObject
    {
        #region 工厂方法

        /// <summary>
        /// 创建新的 GroupInfo 对象。
        /// </summary>
        /// <param name="groupId">GroupId 属性的初始值。</param>
        /// <param name="groupName">GroupName 属性的初始值。</param>
        public static GroupInfo CreateGroupInfo(global::System.Int32 groupId, global::System.String groupName)
        {
            GroupInfo groupInfo = new GroupInfo();
            groupInfo.GroupId = groupId;
            groupInfo.GroupName = groupName;
            return groupInfo;
        }

        #endregion

        #region 基元属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 GroupId
        {
            get
            {
                return _GroupId;
            }
            set
            {
                if (_GroupId != value)
                {
                    OnGroupIdChanging(value);
                    ReportPropertyChanging("GroupId");
                    _GroupId = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("GroupId");
                    OnGroupIdChanged();
                }
            }
        }
        private global::System.Int32 _GroupId;
        partial void OnGroupIdChanging(global::System.Int32 value);
        partial void OnGroupIdChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String GroupName
        {
            get
            {
                return _GroupName;
            }
            set
            {
                OnGroupNameChanging(value);
                ReportPropertyChanging("GroupName");
                _GroupName = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("GroupName");
                OnGroupNameChanged();
            }
        }
        private global::System.String _GroupName;
        partial void OnGroupNameChanging(global::System.String value);
        partial void OnGroupNameChanged();

        #endregion

        #region 导航属性

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("EFIce", "FK_ContactInfo_GroupInfo", "ContactInfo")]
        public EntityCollection<ContactInfo> ContactInfo
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<ContactInfo>("EFIce.FK_ContactInfo_GroupInfo", "ContactInfo");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<ContactInfo>("EFIce.FK_ContactInfo_GroupInfo", "ContactInfo", value);
                }
            }
        }

        #endregion

    }

    #endregion

}

PhoneBookObject.cs

c.最后就是设置App.config

测试,用不用预生成视图的结果几乎无任何差别.

我怀疑 预生成视图 没起效果.我删了新引入项目里的.ssdl,.csdl,.msl,.Views.cs文件,项目一样跑起来了.可是,我按文档(.net 4.0 版本的文档)走的啊,没有错.

我在MSDN没找到预生成视图 .net 4.5版本的资料.也许,.net 4.5之前,需要通过手动操作才能提高性能,在.net 4.5及之后已经优化了,使用高版本vs不需要额外设置,所以呢,.net 4.5搭配EF6的性能比之前.net 4的性能要好不少吧?

...也怀疑是因为用的控制台而不是asp.net mvc的关系? 毕竟还是有区别的.

或者,我使用的是EntityFramework6.1.3和.NET Framework 4.5,vs2013(vs2012,vs2015应该也行),建立好.edmx后,PhoneBookModel.edmx已经‘嵌入输出程序集中‘了,.edmx文件包含了.ssdl,.csdl,.msl文件.而 H文说了半天,也就是把.ssdl,.csdl,.msl这三个文件属性的生成操作设为‘嵌入的资源‘. 唯一值得考究的就是PhoneBook.Views.cs视图文件了.它到底有多大作用呢?

希望明白的园友能和我多交流.

时间: 2024-10-07 11:27:46

EntityFramework性能之预生成视图的相关文章

C#:通过Visual Studio项目预生成命令获取SVN版本号

之前有一个winfrom项目,想要通过获取SVN版本号作为程序的内部编译版本号.经过一系列研究,得出了一些经验,特总结成一篇博客. 方法一:通过SVN命令获取版本号 类似地,我在项目中添加了一个名为"Version_inf.bat"的用于生成版本号的批处理文件,并设置它的属性为始终复制到输出目录.代码如下: 1 svn info>SVN_Version.dll 2 findstr “Revision” SVN_Version.dll 这段脚本的意思是通过“svn info”命令获

利用VS的预生成事件获取SVN版本作为项目内部版本号

VS中的Properties下的AssemblyInfo.cs可以设置相应的版本号.下面是AssemblyInfo.cs设置版本的方式. [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] 但是,这个需要每次都设定,而且与SVN上的版本号并不一致,追塑起来不是很方便.所以就想着取SVN上的版本号作为项目的版本号.要得到SVN的版本号,可以在SVN的节眯下,

MWeb 1.6 发布!Dark Mode、全文搜寻、发布到Wordpress、Evernote 等支持更新、编辑/预览视图模式等

Dark Mode 使用 View - Dark Mode 或快捷键 CMD + Option + L 开启或关闭 Dark Mode.可以在设置中设置 Dark Mode 状态下编辑器所使用的样式,如下图. 全文搜寻 文档库模式会搜寻文档库中的所有文档,外部模式只搜寻当前选择的文件夹下的文档.为方便全键盘使用,增加了 Focus Search Field(CMD + Shift + F) 和 Focus Editor(CMD + Shift + E) 两个快捷键. 发布服务支持更新 发布到 W

c#生成方案里预生成拷贝文件

我们在做项目时,可能是多人合作,这样每个人的目录层次级别是不一样的,如果用VS自带的OUTPUT输出目录,改变路径,把DLL集中生成到一个文件夹,那么不同人的机器上结果是不一样的,这就造成了,我这台机器上设置正确,其他人设置就会不对,目录层次就错了,为了避免这样的情况,我们就会用预生成执行命令这样来操作,也就是我无论你放几层目录,始终是这样的,如: D:\aaa\123\  项目 ,我们以项目为节点,在项目下面是我们的程序文件,也就是别人拿到此文件是D:\ 项目,这要目录也无所谓了 操作方法: 

日志表定时生成视图

实现日志表定时生成视图,为实现日志数据可视化分析提供基础 USE [ThreeToOne] GO /****** Object:  StoredProcedure [dbo].[WTO_Scan_view1]    Script Date: 01/08/2019 15:23:18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= --

SqlServer性能优化 手工性能收集动态管理视图(三)

动态管理视图: 具体的实例语句:  --关于语句执行的基本情况 select * from sys.dm_exec_query_stats  --动态管理函数  需要提供参数  select top 10 execution_count,total_worker_time,t.text,total_worker_time/execution_count      as avgcpu from  sys.dm_exec_query_stats as s  cross apply sys.dm_ex

EntityFramework 性能简单测试

EntityFramework 的便捷不多阐述, 就他的性能来测试了下  不做评论,   缓存机制确实还不错  .... 简单的查询一条数据 1 public static IM_CallRecord GetEFData() 2 { 3 using (ModelContainer mv = new ModelContainer()) 4 { 5 return (from c in mv.IM_CallRecord where c.id == 12356 select c).SingleOrDef

Entityframework 性能优化

在谈谈EF的性能优化之前请允许笔者废话几句.虽然说笔者以前有接触EF,但真正意义上的接触EF算是今年的8月份吧!那时公司里面有一个产品模块化的项目需要用到ORM.当时有两个选择1.EF,2.NHibernate. 说实在的两者的口碑都不怎么样...最后我还是支持了下微软的EF,毕竟做.Net开发用自家的会方便很多把.一开始在网上查得的一些博文会说EF各种性能不好!(PS:今天跟客户谈项目的时候又被喷了)不过我还是傻里傻气的保持乐观的态度,性能不好就想办法让它好起来!!!不做怎么知道呢!下面我一些

oracle AWR性能监控报告生成方法

目前相当一部分公司会用到oracle,在做性能测试的时候,对数据库的监控很重要,那么这里先介绍下如何生成oracle自带的awr监控报告,而具体报告的内容分析会放在后续的博客中 oracle性能分析入门学习中,遇到oracle数据库的性能问题,一般首要的步骤就是导出AWR的分析报告,awr报告是oracle自带的监控报告,会自带很多监控数据,那么本篇博客就是介绍如何导出awr报告 1.首先需要进入oracle用户,linux命令:su oracle,可以看到从root用户改为oracle用户 2