0

I'm trying to create client server application using WCF data services and entity Framework database first for the server side and WPF with MVVM for the client side. All this was good except in one step , I implemented a partial class for each entity (to avoid auto generated code problem) to implement a common interface named IPrimaryModel that implements all common properties in each table such as Id , CreattionDate and so on below is an example:

public Interface IPrimaryModel
{
    string Id { get; set; }
    string Observation { get; set; }
    System.DateTime Creation_Date { get; set; }
    Nullable<System.DateTime> Update_Date { get; set; }
}

and for each entity :

public partial class Brand : IPrimaryModel {}

for the MVVM pattern i created a basic generic class for all View-Models which are related to each entity represented by the WCF and EF

public abstract class PrimaryEntityVm<T> : DgVmSource where T : class, IPrimaryModel, new()
{}

but the problem is : i can't find a way to use the IPrimaryModel of the WCF in the client side and i need to use this interface for common operations to avoid write same code multiple times such as this code

criteria.Add(new Predicate<T>(x => x.Id != null && x.Id.Contains(ObservationFilter)));

Thank you for help

AbuDawood
  • 745
  • 7
  • 22
  • You can create new project where you put your interface. Then reference that project in the WCF and client side. – Fabio Jul 30 '16 at 18:10
  • Thank you for your answer , but this also will not help always can't not be used as type parameter 'T' bcs there is no implicit ref conversion .. – AbuDawood Jul 30 '16 at 18:35
  • I tried to use the same wcf project but this also will create a conflict error .. – AbuDawood Jul 30 '16 at 18:40
  • I see, then I think you can create some "facade" class for type generated by WCF. Or use cusotm proxy generation for WCF. – Fabio Jul 30 '16 at 18:48
  • At the end of the day, you'll run into the EF restriction that it doesn't support generics. But it's not entirely clear to me what you want with `Predicate`. – Gert Arnold Jul 30 '16 at 23:37
  • I extract db result as ObservableCollection than i convert it to CollectionViewList and use predicate in filtering .. Generic class here is the base class of the VM(s) , it is related to my view models not EF, Any help? – AbuDawood Jul 30 '16 at 23:52
  • I found this [topic](https://weblog.west-wind.com/posts/2007/Dec/14/ClientBaseT-and-a-Common-Base-Class) but it seems very difficult to understand – AbuDawood Jul 30 '16 at 23:53

1 Answers1

0

I found the solution by using dynamic object type with predicates

criteria.Add(new Predicate<dynamic>(x => x.Id != null && x.Id.Contains(ObservationFilter)));

by this way compliant will not verify if the common properties are belong to selected object until runtime runs !
source

Second Method A powerful way http://www.puresolutions-online.com/Blog/December-2014/Extending-WCF-Data-Service-Entities

Community
  • 1
  • 1
AbuDawood
  • 745
  • 7
  • 22