AdventureWorks无法创建ado.net实体数据模型

Gre*_*g B 7 sql-server ado.net visual-studio-2010

我正在尝试使用microsoft的示例数据库AdventureWorks2008R2 ...当我尝试创建ADO.NET实体数据模型时,我收到此错误:

Unable to generate the model because of the following exception: 'The table 'C:\USERS\XXXX\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\ANOTHERWORKS\ANOTHERWORKS\APP_DATA\ADVENTUREWORKS2008R2_DATA.MDF.Production.Document' was referenced by a relationship, but was not found.'.
Loading metadata from the database took 00:00:06.2308687.
Generating the model took 00:00:04.5808698.
Added the connection string to the Web.Config file.
Successfully registered the assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the Web.Config file.
Writing the .edmx file took 00:00:00.0015898.
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这个问题?或者知道某个地方我可以下载这个数据库的工作版本(其他时间:http://msftdbprodsamples.codeplex.com/releases/view/59211这是我得到它的地方)

或者有人可以指向我可以下载并使用实体框架的示例数据库.

Paw*_*wel 3

编辑

新的 EF 设计器(此处提供 Beta 1 )不会尝试创建与不存在的表的关系,因此您将获得一个模型,其中无效的实体类型/集和关系被注释掉,而不是错误和空模型。

**

我在 AdventureWorks for Sql Server 2012 中查看了它,但我认为这与您在 2008R2/ 中遇到的情况相同。这里的问题是 Production.Document 表有一个 HierarchyId 类型的键,而 EF 当前不支持 HierarchyId 类型。创建模型时,EF 会忽略它不理解的类型列,但是如果它不理解关键列,它将从模型中排除整个实体。对于排除的实体,当您使用 Xml/文本编辑器打开模型时,您应该能够找到它们在模型中被注释掉。在这种特殊情况下,将会看到以下内容:

<EntityContainer Name="AdventureWorksModelStoreContainer" />
    <!--Errors Found During Generation:
  warning 6005: The data type 'hierarchyid' is currently not supported for the target .NET Framework version; the column 'DocumentNode' in table 'AdventureWorks.Production.Document' was excluded.
  warning 6031: The column 'DocumentNode' on the table/view 'AdventureWorks.Production.Document' was excluded, and is a key column.  The table/view has been excluded.  Please fix the entity in the schema file, and uncomment.

  <EntityType Name="Document">
    <Property Name="DocumentLevel" Type="smallint" StoreGeneratedPattern="Computed" />
    <Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" />
    <Property Name="Owner" Type="int" Nullable="false" />
    <Property Name="FolderFlag" Type="bit" Nullable="false" />
    <Property Name="FileName" Type="nvarchar" Nullable="false" MaxLength="400" />
    <Property Name="FileExtension" Type="nvarchar" Nullable="false" MaxLength="8" />
    <Property Name="Revision" Type="nchar" Nullable="false" MaxLength="5" />
    <Property Name="ChangeNumber" Type="int" Nullable="false" />
    <Property Name="Status" Type="tinyint" Nullable="false" />
    <Property Name="DocumentSummary" Type="nvarchar(max)" />
    <Property Name="Document" Type="varbinary(max)" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>-->
  </Schema>
Run Code Online (Sandbox Code Playgroud)

请注意此警告:
警告 6031:表/视图“AdventureWorks.Production.Document”上的列“DocumentNode”已被排除,并且是关键列。表/视图已被排除。请修复架构文件中的实体,并取消注释。

现在,在 AdventureWorks 数据库中,Production.Document 表由 Production.ProductDocument 表引用。由于没有为 Production.Document 表创建实体,EF 无法从 Production.ProductDocument 实体创建引用,因此“Production.Document”由关系引用,但无法找到。错误。

由于 EF 无法真正“按原样”使用 Production.Document 表,因此最简单的解决方法是在从实体生成模型时排除此实体 - 检查向导中除 Production.Document 之外的所有表,然后就可以开始了。EF 将忽略对此实体的所有引用,因为您排除了它,因此应该不会出现错误。

链接到 Entity Framework Codeplex 站点上的相关工作项