views:

33

answers:

3

I want to have a field in my entity where the returned data comes from a class function in mydomainservice and not from the database.

The reason is that I want to generate an image URL (Silverlight bind) based rather loosely upon other fields in a table

How can I obtain that ?

+1  A: 

You can extend your linq2sql generated class by making a partial class with the same name (in the same namespace) and putting the method in that file.

klausbyskov
+1  A: 

Declare a partial class with the same name as the entity class and in the same assembly. Declare your function/property as usual.

Jay
You are talking about the adding a partial class to the Dataclasses.designes.cs ?How do you decorate the [Column(Storage= ???]
Martin
+2  A: 

The other two have mentioned a partial class. They are correct. Here's an example...

public partial class MyImage
{
    public string CompleteUrl
    {
        get { return string.Format("http://{0}/{1}/{2}.png", Host, Folder, Filename); }
    }
}

This would assume that you already have columns named "Host", "Folder", and "Filename" in your database, and those have already been mapped to the appropriate columns.

L2S generates partial classes for all of its implementations. You shouldn't be doing your own mapping. These partial classes allow you to create a new file (with ClassName.cs) that will allow you to extend the functionality of your domain objects.

Jarrett Meyer
Thanks a lot, I'll have to experience a bit to see what I get :)
Martin
Yepp!It really works, and so simple. Reading tons of documentation really got be nowhere
Martin