Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdventureWorks can't create ado.net entity data model

I'm trying to use microsoft's sample database AdventureWorks2008R2... when I try to create the 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.

Anyone encountered and fixed this? Or knows somewhere I can download a working version of this database ( other then: http://msftdbprodsamples.codeplex.com/releases/view/59211 which is where I got it )

Or can someone point to a sample database I can download and use around with entity framework.

like image 575
Greg B Avatar asked Jun 21 '12 17:06

Greg B


People also ask

How do I add ado net entity data model?

Create the ADO.NET Entity Data ModelRight-click on your project in the Solution Explorer window and select the menu option Add -> New Item. In the Add New Item dialog, select the Data category. Select the ADO.NET Entity Data Model template, give the Entity Data Model the name Northwind. edmx, and click the Add button.

What is Microsoft AdventureWorks?

AdventureWorks Database is a Microsoft product sample for an online transaction processing (OLTP) database. The AdventureWorks Database supports a fictitious, multinational manufacturing company called Adventure Works Cycles.

What is ado net entity data model?

The Entity Data Model (EDM) is a set of concepts that describe the structure of data, regardless of its stored form. The EDM borrows from the Entity-Relationship Model described by Peter Chen in 1976, but it also builds on the Entity-Relationship Model and extends its traditional uses.

What is the size of AdventureWorks database?

AdventureWorks (OLTP) full database backups Download size is 883 MB.


1 Answers

EDIT

The new EF designer (Beta 1 available here) will not try creating relationships to non-existing tables so instead of the error and empty model you will get a model where invalid entity types/sets and relationships are commented out.

**

I looked at it for AdventureWorks for Sql Server 2012 but I think it is the same thing you hit for 2008R2/ The issue here is that the Production.Document table has a key that is of HierarchyId type and EF currently does not support HierarchyId type. EF ignores columns of types it does not understand when creating the model however if it does not understand a key column it will exclude the entire entity from the model. For excluded entities you should be able to find them commented out in the model when you open it with an Xml/Text editor. In this particular case this is what 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>

Notice this warning:
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.

Now in the AdventureWorks database the Production.Document table is referenced by Production.ProductDocument table. Since no entity for Production.Document table was created EF is unable to create the reference from Production.ProductDocument entity and hence the "Production.Document' is referenced by a relationship, but cannot be found.' error.

Since the Production.Document table cannot be really used "as is" by EF the easiest workaround is to exclude this entity when generating the model from entity - check all tables but Production.Document in the wizard and you should be good to go. EF will ignore all references to this entity since you excluded it and therefore there should be no error.

Link to a related work item on Entity Framework codeplex site

like image 178
Pawel Avatar answered Nov 15 '22 10:11

Pawel