Results 1 to 2 of 2

Thread: LINQ to SQL. Allowing 'get' property to be translated to sql

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    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.


  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width