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