I have a RPC that I call which passes up an entity. On the server, the code looks like this:
[AllowRpc]
public static object Test1(IPrincipal pPrincipal, EntityManager pPm, params Object[] pArgs)
{
Customer cust = (Customer)pArgs[0];
cust.ContactName = "Peter Pan";
pPm.SaveChanges{new [] cust });
return cust;
}
On the line where Peter Pan is assigned to the ContactName, an error of Object Ref not set to an instance of an object error is thrown.
If I add a line which attaches it to the pPm, it no longer throws an error. This would be fine, except in some instances, there are related items already attached to the entity. In this case, when it gets to the line which attaches the entity, it throws an error, saying that the related entity is already attached to the Entity Manager. It doesn't make any sense to me why the main entity would not be attached, and the related entity would be attached. Before the RPC call is made, the entity is attached to an EntityManager and saved, so it seems like it should already be attached. The related entities are also saved and attached so it seems like they should come accross the wire in the same entity state as the cust.
I have been unable to resolve this issue.
Greg