cdonner
cdonner

Reputation: 37668

Linq to SQL with Stored Procedures

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?

Upvotes: 2

Views: 1174

Answers (3)

RickNZ
RickNZ

Reputation: 18654

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...)

Upvotes: 0

bruno conde
bruno conde

Reputation: 48265

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

Upvotes: 3

Mark Byers
Mark Byers

Reputation: 838156

Have you added the appropriate using directive?

using System.Data.Linq.Mapping;

Upvotes: 4

Related Questions