AdventureWorks cannot create ado.net entity data model

I'm trying to use the Microsoft AdventureWorks2008R2 sample database ... when I try to create an ADO.NET entity data model, I get this error:

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. 

Has anyone encountered and fixed this? Or somewhere I can download a working version of this database (otherwise: http://msftdbprodsamples.codeplex.com/releases/view/59211 , where I got it)

Or can someone point to a sample database that I can download and use with the entity infrastructure.

+7
source share
1 answer

EDIT

The new EF designer (beta 1 here ) will not try to create relationships with nonexistent tables, so instead of an error and an empty model, you get a model in which invalid types / sets of entities and relationships are commented out.

**

I looked at it for AdventureWorks for Sql Server 2012, but I think it’s the same as you got in 2008R2 / The problem here is that there is a key in the Production.Document table that is of type HierarchyId, and EF is currently time does not support the type HierarchyId. EF ignores type columns that it does not understand when creating the model; however, if it does not understand the key column, it excludes the entire object from the model. For excluded objects, you should be able to find them in models when you open them using the Xml / Text editor. In this particular case, this is what it will see:

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

Pay attention to this warning:
warning 6031: The "DocumentNode" column in the table / view "AdventureWorks.Production.Document" has been excluded and is the key column. Table / view excluded. Correct the object in the schema file and uncomment it.

Now in the AdventureWorks database, the Production.Document table refers to the Production.ProductDocument table. Since no organization has been created for the Production.Document table, EF cannot create a link from the Production.ProductDocument object and, therefore, "Production.Document" refers to the relationship, but cannot be found. "Error.

Since the Production.Document table cannot really be used "as is" with EF, the easiest workaround is to exclude this object when creating the model from the object - check all the tables except Production.Document in the wizard, and you should be good for go. EF ignores all references to this object since you excluded it, and therefore there should be no errors.

Link to a related work item on the Codetex Framework Entity Framework site

+2
source

All Articles