user2514158 user2514158 - 1 year ago 72
C# Question

best way to consume interface that implement entity framework entities in wcf data services

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

Answer Source

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 !