編集
新しい 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 サイトの関連作業項目へのリンク