2012-06-21 61 views
7

我想使用微软的示例数据库AdventureWorks2008R2 ...当我尝试创建ADO.NET实体数据模型我得到这个错误:的AdventureWorks不能创建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这就是我得到它的地方)

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

+0

你们是不是要做到这一点使用SQL Express的一个基于文件的连接字符串? –

回答

2

编辑

新的EF设计(Beta 1的可here)将不会尝试创建到不存在的表的关系,所以不是错误,空模型,你会得到一个模型,其中无效的实体类型/套并且关系被注释掉。

**

我看了它的AdventureWorks对于SQL Server 2012,但我认为这是你打的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.Document表由Production.ProductDocument表引用。由于没有创建Production.Document表的实体,因此EF无法从Production.ProductDocument实体创建参考,因此“Production.Document”被关系引用,但无法找到。错误

由于EF无法“按原样”真正使用Production.Document表,因此最简单的解决方法是在从实体生成模型时排除此实体 - 检查向导中的所有表,但除Production.Document外,应该是好去。因为你排斥它EF会忽略这个实体的所有引用,因此应该有任何错误。

Link to a related work item on Entity Framework codeplex site

相关问题