ef-code-firstcode-firstwcf-ria-servicesef4-code-only

EF Code Only Inheritance on the client


(sorry for my bad english)

In a Silverlight 4 + RIA Services + EF4 Code Only application I have some classes on my DbContext that contain a "IsActive" field - I want to know from the client if a entity have this field and get it. My first thought was to use a interface:

public interface IHasActiveField
{
    bool IsActive {get; set;}
}

public class Data: IHasActiveField
{
    public bool IsActive {get; set;}
}

This work fine on the server but on the client, the RIA generated code do not have any reference to my interface, so I cannot test if (obj is IHasActiveField) - the same happens if I try to inherit from a base class with the IsActive field, on the client side, the class Data always inherit from Entity - I probably could use reflection to see if the field exists or just test for every type (if (obj is Data)) but if a more elegant way is possible, it would be way better :)


Solution

  • The following blog sounds like what you want.

    "All you have to do is use a partial class for your model, and name the file with .shared.cs (or .shared.vb). This file will automatically be copied to the Silverlight project, so whatever is in it will be retained on the client. So with all of the interface implementation in that file, you’re done." http://jeffhandley.com/archive/2009/03/30/ria-services-custom-interfaces.aspx