我正在尝试使用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.
有人遇到过并修好了吗?或者知道某个地方我可以下载这个数据库的工作版本(其他:http://msftdbprodsamples.codeplex.com/releases/view/59211这是我得到它的地方)
或者有人可以指向我可以下载并使用实体框架的示例数据库。
答案 0 :(得分:2)
修改强>
新的EF设计器(Beta 1 available here)将不会尝试创建与不存在的表的关系,因此您将获得一个模型,其中包含错误和空模型,其中评论了无效的实体类型/集和关系进行。
**
我为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.Document表由Production.ProductDocument表引用。由于没有创建Production.Document表的实体,EF无法从Production.ProductDocument实体创建引用,因此“Production.Document”由关系引用,但无法找到。错误。
由于EF不能真正“按原样”使用Production.Document表,因此最简单的解决方法是在从实体生成模型时排除此实体 - 检查向导中的所有表,但是生产。文档应该是好的走。 EF将忽略对该实体的所有引用,因为您将其排除在外,因此不会出现错误。
Link to a related work item on Entity Framework codeplex site