Linq 异常“此提供程序只支持对返回实体或投影(包含所有标识列)的有序查询使用 Skip()...”...
生活随笔
收集整理的這篇文章主要介紹了
Linq 异常“此提供程序只支持对返回实体或投影(包含所有标识列)的有序查询使用 Skip()...”...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題:asp.net使用linq,在sql server 2005下面使用視圖分頁沒有問題,但在sql server 2000下面使用視圖
提示:此提供程序只支持對返回實體或投影(包含所有標識列)的有序查詢使用 Skip(),這種查詢為單表(非聯接)查詢,或者為 Distinct、Except、Intersect 或 Union (非 Concat)操作。
原因:LINQ生成分布查詢語句時,需要依賴主鍵。那么,如下情況將導致出現上述錯誤 1)數據表未定義主鍵 2)查詢對象為視圖對象
奇怪的是:在sql server 2005里,能識別視圖中某個表的主鍵,不會提示錯誤,到sql server 2000下面就提示錯誤。
反正也不能回避問題,再網上搜索了一下相關的問題,確實很多人遇到,主要是試圖的主鍵問題,表的主鍵很容易解決,在sql server里視圖是沒有主鍵的。
網上的一種解決方案能解決這個問題:更改LINQ to SQL 類。
找到LINQ to SQL 類的文件,下面有個xxx.designer.cs,找到相應的試圖:
Code
????public?System.Data.Linq.Table<ProductInfo>?ProductInfo
????{
????????get
????????{
????????????return?this.GetTable<ProductInfo>();
????????}
????}
????
????public?System.Data.Linq.Table<Product_Class_View>?Product_Class_View
????{
????????get
????????{
????????????return?this.GetTable<Product_Class_View>();
????????}
????}右鍵轉到定義:會有這個對象的定義
[Table(Name="dbo.Product_Class_View")]
public?partial?class?Product_Class_View
{
????
????private?int?_ProID;
????
????private?string?_ProName;
????
????private?System.Nullable<int>?_CateID;
????
????private?System.Nullable<int>?_ClassID;
????
????private?string?_ImgUrl;
????
????private?string?_Summary;
????
????private?string?_Content;
????
????private?System.Nullable<int>?_OrdNum;
????
????private?System.Nullable<int>?_ViewNum;
????
????private?System.Nullable<int>?_InfoVer;
????
????private?System.Nullable<System.DateTime>?_CreateDate;
????
????private?string?_ClassName;
????
????public?Product_Class_View()
????{
????}
????
????[Column(Storage="_ProID",?DbType="Int?NOT?NULL",?IsDbGenerated=true,IsPrimaryKey=true)]
????public?int?ProID
????{
????????get
????????{
????????????return?this._ProID;
????????}
????????set
????????{
????????????if?((this._ProID?!=?value))
????????????{
????????????????this._ProID?=?value;
????????????}
????????}
????}
????
????[Column(Storage="_ProName",?DbType="NVarChar(255)")]
????public?string?ProName
????{
????????get
????????{
????????????return?this._ProName;
????????}
????????set
????????{
????????????if?((this._ProName?!=?value))
????????????{
????????????????this._ProName?=?value;
????????????}
????????}
????}
????
????[Column(Storage="_CateID",?DbType="Int")]
????public?System.Nullable<int>?CateID
????{
????????get
????????{
????????????return?this._CateID;
????????}
????????set
????????{
????????????if?((this._CateID?!=?value))
????????????{
????????????????this._CateID?=?value;
????????????}
????????}
????}
????
關鍵是這一句:?[Column(Storage="_ProID", DbType="Int NOT NULL", IsDbGenerated=true,IsPrimaryKey=true)]
加上加粗部分的就可以了。
提示:此提供程序只支持對返回實體或投影(包含所有標識列)的有序查詢使用 Skip(),這種查詢為單表(非聯接)查詢,或者為 Distinct、Except、Intersect 或 Union (非 Concat)操作。
原因:LINQ生成分布查詢語句時,需要依賴主鍵。那么,如下情況將導致出現上述錯誤 1)數據表未定義主鍵 2)查詢對象為視圖對象
奇怪的是:在sql server 2005里,能識別視圖中某個表的主鍵,不會提示錯誤,到sql server 2000下面就提示錯誤。
反正也不能回避問題,再網上搜索了一下相關的問題,確實很多人遇到,主要是試圖的主鍵問題,表的主鍵很容易解決,在sql server里視圖是沒有主鍵的。
網上的一種解決方案能解決這個問題:更改LINQ to SQL 類。
找到LINQ to SQL 類的文件,下面有個xxx.designer.cs,找到相應的試圖:
Code
????public?System.Data.Linq.Table<ProductInfo>?ProductInfo
????{
????????get
????????{
????????????return?this.GetTable<ProductInfo>();
????????}
????}
????
????public?System.Data.Linq.Table<Product_Class_View>?Product_Class_View
????{
????????get
????????{
????????????return?this.GetTable<Product_Class_View>();
????????}
????}右鍵轉到定義:會有這個對象的定義
[Table(Name="dbo.Product_Class_View")]
public?partial?class?Product_Class_View
{
????
????private?int?_ProID;
????
????private?string?_ProName;
????
????private?System.Nullable<int>?_CateID;
????
????private?System.Nullable<int>?_ClassID;
????
????private?string?_ImgUrl;
????
????private?string?_Summary;
????
????private?string?_Content;
????
????private?System.Nullable<int>?_OrdNum;
????
????private?System.Nullable<int>?_ViewNum;
????
????private?System.Nullable<int>?_InfoVer;
????
????private?System.Nullable<System.DateTime>?_CreateDate;
????
????private?string?_ClassName;
????
????public?Product_Class_View()
????{
????}
????
????[Column(Storage="_ProID",?DbType="Int?NOT?NULL",?IsDbGenerated=true,IsPrimaryKey=true)]
????public?int?ProID
????{
????????get
????????{
????????????return?this._ProID;
????????}
????????set
????????{
????????????if?((this._ProID?!=?value))
????????????{
????????????????this._ProID?=?value;
????????????}
????????}
????}
????
????[Column(Storage="_ProName",?DbType="NVarChar(255)")]
????public?string?ProName
????{
????????get
????????{
????????????return?this._ProName;
????????}
????????set
????????{
????????????if?((this._ProName?!=?value))
????????????{
????????????????this._ProName?=?value;
????????????}
????????}
????}
????
????[Column(Storage="_CateID",?DbType="Int")]
????public?System.Nullable<int>?CateID
????{
????????get
????????{
????????????return?this._CateID;
????????}
????????set
????????{
????????????if?((this._CateID?!=?value))
????????????{
????????????????this._CateID?=?value;
????????????}
????????}
????}
????
關鍵是這一句:?[Column(Storage="_ProID", DbType="Int NOT NULL", IsDbGenerated=true,IsPrimaryKey=true)]
加上加粗部分的就可以了。
轉載于:https://www.cnblogs.com/7788/archive/2009/09/24/1573229.html
總結
以上是生活随笔為你收集整理的Linq 异常“此提供程序只支持对返回实体或投影(包含所有标识列)的有序查询使用 Skip()...”...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态注册OCX
- 下一篇: Flex 3 与 Flex 4 beta