|
-
Sep 15th, 2009, 08:39 AM
#1
Thread Starter
Not NoteMe
LINQ to SQL. Allowing 'get' property to be translated to sql
I have a table of warranties in my SQL database. These are represented by Warranty objects generated via LINQ to SQL. I've extended the partial classes generated to have a new property called Address, which is a combination of each address line field. (There is a bit of logic in there too through).
Code:
public string Address
{
get
{
return (!string.IsNullOrEmpty(AddressLine1) ? AddressLine1 + " " : "") +
(!string.IsNullOrEmpty(AddressLine2) ? AddressLine2 + " " : "") +
(!string.IsNullOrEmpty(AddressLine3) ? AddressLine3 + " " : "") +
(!string.IsNullOrEmpty(AddressLine4) ? AddressLine4 + " " : "") +
(!string.IsNullOrEmpty(AddressLine5) ? AddressLine5 + " " : "") +
(!string.IsNullOrEmpty(Postcode) ? Postcode + " " : "");
}
}
I get the following error if i try and build a LINQ query using the property, which is kind of expected, but also kind of annoying!
Code:
System.NotSupportedException: The member 'HomeserveSharedClasses.DAL.Warranty.Address' has no supported translation to SQL.
What do i have to do in order for this property getter to work in a LINQ query?
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 20th, 2009, 03:18 AM
#2
Re: LINQ to SQL. Allowing 'get' property to be translated to sql
Make sure that the L2S class and your extended class have the same namespace. I've created custom properties in the same way as you before, so I don't think the problem should be any code there, just the namespaces.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|