views:

78

answers:

3

I want to add custom (compound and read-only) attributes to my stored procedure results class. When I did that, I got the error

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

I then found this blog post - the author suggests that decorating the partial class with the [Table] attribute will resolve the problem.

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

But then I got this error:

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

Is there a way to do this?

+2  A: 

Have you added the appropriate using directive?

using System.Data.Linq.Mapping;
Mark Byers
2 correct answers - only one can get the check mark. Thanks.
cdonner
+2  A: 

Be sure that you're using System.Data.Linq.Mapping; with the appropriate assembly referenced: System.Data.Linq.dll.

bruno conde
A: 

I use read-only custom attributes in my stored procedure result classes all the time, without trouble.

However, I don't rely on auto-generated / drag-and-drop mechanisms. Just code it yourself, and you may find the problem goes away.

(oh, and as the error message says, you're missing a using directive...)

RickNZ