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

7

我正在尝试使用微软的示例数据库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.

有人遇到并解决了这个问题吗?或者知道我可以下载一个工作版本的这个数据库的地方(除了:http://msftdbprodsamples.codeplex.com/releases/view/59211,那是我得到它的地方)

或者有人可以指向一个示例数据库,我可以使用实体框架进行下载和使用。


你是在尝试使用基于文件的连接字符串和SQL Express来完成这个任务吗? - Jon Seigel
1个回答

3

编辑

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

**

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

<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>

注意此警告:
警告 6031:表/视图 'AdventureWorks.Production.Document' 上的列'DocumentNode'已被排除,是关键列。该表/视图已被排除。请在模式文件中修复实体并取消注释。
现在,在AdventureWorks数据库中,Production.ProductDocument表引用了Production.Document表。由于没有为Production.Document表创建实体,因此EF无法从Production.ProductDocument实体创建引用,因此会出现“引用关系中引用了“Production.Document”,但找不到”的错误。
由于EF无法真正使用Production.Document表,最简单的解决方法是在从实体生成模型时排除此实体-在向导中检查所有表格,但Production.Document不包括在内,这样您就可以放心使用了。由于您已经将其排除在外,EF将忽略对此实体的所有引用,因此不应出现错误。 Entity Framework codeplex网站上相关工作项的链接

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接