2009-11-29 69 views
2

我想將自定義(複合和只讀)屬性添加到我的存儲過程結果類。當我這樣做,我得到了錯誤Linq to SQL with Stored Procedures

LINQ - Cannot assign value to member XXX. It does not define a setter. 

然後我發現這個blog post - 筆者認爲,與[表]屬性裝飾部分類將解決此問題。

1: [Table] 
2: partial class GetContactsResult 
3: { 
4:  public string FullName 
5:  { 
6:   get 
7:   { 
8:    return FirstName + " " + LastName; 
9:   } 
10:  } 
11: } 

但後來我得到這個錯誤:

The type or namespace name 'Table' could not be found (are you missing 
a using directive or an assembly reference?) 

有沒有辦法做到這一點?

回答

4

您是否添加了相應的使用指令?

using System.Data.Linq.Mapping; 
+0

2正確答案 - 只有一個能獲得複選標記。謝謝。 – cdonner 2009-11-29 23:50:02

3

確保你using System.Data.Linq.Mapping;與引用相應的組件:System.Data.Linq.dll

0

我一直在我的存儲過程結果類中使用只讀自定義屬性,沒有任何問題。

但是,我不依賴於自動生成/拖放機制。只需編寫它自己,你可能會發現問題消失。

(哦,和錯誤消息說,你是missing a using directive ...)