读书人

ef 生成异常:警告 6002: 表/视图 未定

发布时间: 2012-06-07 15:05:14 作者: rapoo

ef 生成错误:警告 6002: 表/视图 未定义主键

C# code
 <!--生成过程中发现错误:      警告 6002: 表/视图“Northwind.dbo.Category Sales for 1997”未定义主键。已推断出该键,并将定义创建为只读的表/视图。      -->        <EntityType Name="Category Sales for 1997">          <Key>            <PropertyRef Name="CategoryName" />          </Key>          <Property Name="CategoryName" Type="nvarchar" Nullable="false" MaxLength="15" />          <Property Name="CategorySales" Type="money" />        </EntityType>        <!--生成过程中发现错误:      警告 6002: 表/视图“Northwind.dbo.Current Product List”未定义主键。已推断出该键,并将定义创建为只读的表/视图。      -->        <EntityType Name="Current Product List">          <Key>            <PropertyRef Name="ProductID" />            <PropertyRef Name="ProductName" />          </Key>          <Property Name="ProductID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />          <Property Name="ProductName" Type="nvarchar" Nullable="false" MaxLength="40" />        </EntityType>        <!--生成过程中发现错误:      警告 6002: 表/视图“Northwind.dbo.Customer and Suppliers by City”未定义主键。已推断出该键,并将定义创建为只读的表/视图。      -->        <EntityType Name="Customer and Suppliers by City">          <Key>            <PropertyRef Name="CompanyName" />            <PropertyRef Name="Relationship" />          </Key>          <Property Name="City" Type="nvarchar" MaxLength="15" />          <Property Name="CompanyName" Type="nvarchar" Nullable="false" MaxLength="40" />          <Property Name="ContactName" Type="nvarchar" MaxLength="30" />          <Property Name="Relationship" Type="varchar" Nullable="false" MaxLength="9" />        </EntityType>

这是什么问题呢???

[解决办法]
在视图中包含主键,当然,这也不完全是错误,你收到的是警告,如果你的视图只是只读的,也可以不理会。
[解决办法]
以你的第一个为例:
XML code
        <EntityType Name="Category Sales for 1997">          <Key>            <PropertyRef Name="CategoryName" />          </Key>          <Property Name="CategoryName" Type="nvarchar" Nullable="false" MaxLength="15" />          <Property Name="CategorySales" Type="money" />        </EntityType> 

读书人网 >.NET

热点推荐