7

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を入手しました)

または、誰かが私がダウンロードしてエンティティ フレームワークで使用できるサンプル データベースを指摘できますか。

4

1 に答える 1

3

編集

新しい EF デザイナー (ベータ 1はこちらから入手可能) は、存在しないテーブルへのリレーションシップを作成しようとしないため、エラーや空のモデルの代わりに、無効なエンティティ タイプ/セットおよびリレーションシップがコメント アウトされたモデルが取得されます。

**

AdventureWorks for Sql Server 2012 について調べましたが、2008R2 でヒットしたのと同じだと思います。ここでの問題は、Production.Document テーブルに HierarchyId 型のキーがあり、EF は現在 HierarchyId 型をサポートしていないことです。EF は、モデルの作成時に理解できない型の列を無視しますが、キー列を理解していない場合、エンティティ全体をモデルから除外します。除外されたエンティティの場合、Xml/テキスト エディタでモデルを開くと、モデル内でコメント アウトされていることがわかるはずです。この特定のケースでは、次のように表示されます。

<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」はリレーションシップによって参照されていますが、見つかりません。エラー。

Production.Document テーブルは実際には EF で「そのまま」使用できないため、最も簡単な回避策は、エンティティからモデルを生成するときにこのエンティティを除外することです。ウィザードで Production.Document 以外のすべてのテーブルを確認してください。このエンティティを除外したため、EF はこのエンティティへのすべての参照を無視するため、エラーは発生しません。

Entity Framework codeplex サイトの関連作業項目へのリンク

于 2012-12-27T06:27:38.787 に答える