views:

525

answers:

1

I have a WCF service that generates loads Entity Framework objects (as well as some other structs and simple classes used to lighten the load) and sends them over to a client application.

I have changed 2 of the classes to implement an interface so that I can reference them in my application as a single object type. Much like this example: http://stackoverflow.com/questions/523409/is-it-possible-to-force-properties-generated-by-entity-framework-to-implement-int

However, the interface type is not added to my WCF service proxy client thingymebob as it is not directly referenced in the objects that are being sent back over the wire.

Therefore in my application that uses the service proxy classes, I can't cast or reference my interface..

Any ideas what I'm missing?

Here's some example code:

//ASSEMBLY/PROJECT 1 -- EF data model

namespace Model
{
    public interface ISecurable
    {
        [DataMember]
        long AccessMask { get; set; }
    }

    //partial class extending EF generated class
    //there is also a class defined as "public partial class Company : ISecurable"
 public partial class Chart : ISecurable
 {
  private long _AccessMask = 0;
  public long AccessMask
  {
   get { return _AccessMask; }
   set { _AccessMask = value; }
  }

  public void GetPermission(Guid userId)
  {
   ChartEntityModel model = new ChartEntityModel();
   Task task = model.Task_GetMaskForObject(_ChartId, userId).FirstOrDefault();
   _AccessMask = (task == null) ? 0 : task.AccessMask;
  }
 }
}

//ASSEMBLY/PROJECT 2 -- WCF web service
namespace ChartService
{
    public Chart GetChart(Guid chartId, Guid userId)
    {
         Chart chart = LoadChartWithEF(chartId);
         chart.GetPermission(userId); //load chart perms
         return chart; //send it over the wire
    }
}
+1  A: 

Interfaces won't come across as separate entities in your WSDL - they will simply have their methods and properties added to the object that exposes them.

What you want to accomplish you can do using abstract classes. These will come across as distinct entities.

Good luck. Let us know how you decided to proceed.

Anderson Imes
you are correct, there is no answer to this problem. An entity framework partial cannot inherit from an abstract class (or any class for that matter, that isn't part of the same entity model). So in my model, I am still using the interface to keep my structure sorted, but in my client application, I'm just using reflection to check for properties (there are only 2) and sending objects back blindly. The WCF service methods will fail anyway if invalid object param is passed to it anyway... no biggy.Cheers.
misteraidan