views:

15

answers:

1

I have a custom field that I've added to one of my EF entities in a shared.cs file like so:

public partial class Content
{
    public int Test = 5;
}

On the client side, the OnCreated handler for that same class looks like this:

partial void OnCreated()
{
    this.Test = 42;
}

I've added an event handler to the SavingChanges event for the context on the server like this:

partial void OnContextCreated()
{
    this.SavingChanges += (sender, e) =>
    {
        foreach (object o in GetChangedEntities())
        {
            if (o is Content)
            {
                // Break to see what the value of Test is;
            }
        }
    }
}

When I break at the comment (which is not really a comment my code :), the value of Test is always 5. In fact, I can't seem to set it to 42 anywhere on the client and have that value make it to the server.

I have set breakpoints all over the place, and the value is definitely being set to 42 on the client-side. Is there something that I'm doing wrong, or is this behavior just not supported? Incidentally, I've also tried this as a property instead of a field--just in case.

+1  A: 

I needed to mark my property/field as a [DataMember] like this:

public partial class Content
{
    [DataMember]
    public int Test = 5;
}

and then move it out of the shared.cs file to a CustomProperties.cs (or similar) file in the server project to avoid multiple delcarations. Now it crosses the wire just fine.

David Moye