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 b开发者_如何学Cind) based rather loosely upon other fields in a table
How can I obtain that ?
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.
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.
Declare a partial
class with the same name as the entity class and in the same assembly. Declare your function/property as usual.
精彩评论