0

Well, I have a partial class that I use as POCO entity, but I am using it too as DTO to transfer the data from the server to the client with WCF. This class has only the properties that I need to store the data from the database.

However, in my client side, I would need that this classes implements in the client side the notify property changed, to use in my WPF MVVM project.

I would like to know if it is possible that having the extended class, if it is the same class or not. I mean that I would like to avoid the needed to pass the information from my class to my extended class. I would like that this two classes are the same. My idea would be to have in an assembly the basic class as DTO and in another assembly the extended class, so the client would use this extended assembly but it would be the same class, so I can assing the class that I receive from the service to the extended class without needing any conversion.

Thank you so much.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193
  • Possible duplicate of [Is it possible to have two partial classes in different assemblies represent the same class?](http://stackoverflow.com/questions/647385/is-it-possible-to-have-two-partial-classes-in-different-assemblies-represent-the) – Steven Rands Dec 22 '15 at 16:17
  • A decorator fits well here. http://www.dofactory.com/net/decorator-design-pattern – E-Bat Dec 22 '15 at 16:34

2 Answers2

2

If you are using the entity as DTO you should only use it as DTO, meaning only to transfer from the server to the client, and in the client you should create another model, and then map the DTO to the model in the client. Therefore in the model you can implement what ever you like.

Lets say you have the following entity of Person:

public Person
{
    public string Name { get; set; }
    public DateTime BirthDate { get; set; }
}

Your DTO will be like this:

[DataContract]
public class PersonDTO
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public DateTime BirthDate { get; set; }
}

And your model in the client:

public PersonModel : INotifyPropertyChanged
{
    public string Name { get; set; }
    public DateTime BirthDate { get; set; }
}

In that way you separate the logic between the DTO and the model, because the whole point with DTO is to pass low capacity of data.

Now, in order to map from entity to DTO or from DTO to model you can do it manually, or you can check the AutoMapper here : http://automapper.org/.

Hope it helped.

Golan Kiviti
  • 3,895
  • 7
  • 38
  • 63
0

Create another project (for instance called Solution.Infrastructure) which comprises of files being exchanged. In WCF and WPF project add references to Inrrastructure. As a result both will use equivalent class and you can effortlessly implement INotifyPropertyChanged. Wpf will be able to take advantage of it, WCF will actually never benefit from UI refresh mechanism.

Maximus
  • 3,458
  • 3
  • 16
  • 27
  • Sorry, I have not clear a detail. This project has classes that implement the INotifyPropertyChanged and this classes are used for WCF and WPF? So we could say that the DTO classes implements the INotifyPropertyChanged. Thank you so much. – Álvaro García Dec 23 '15 at 09:13
  • If you send DTO from service and on client side your intent is that those classess refresh UI than let them implement INotifyPropertyChanged and place them in separate project (Infrastucture for instance). WPF will make use of INotifyPropertyChanged, WCF will not since there is no UI. – Maximus Dec 23 '15 at 09:16