If I have an entity in RIA services like this,
[EnableClientAccess]
public class ShapeEntity
{
[Key]
public int Id { get; set; }
[Association("Shapes", "Id", "Id")]
[Include()]
public IEnumerable<SingleShapeEntity> ShapeEntities { get; set; }
}
The problem with the above is that I just want the ShapeEntities to hold information related to the ShapeEntity, but not be its own entity in its own right.
The problem with it being a separate entity is that I add or update something in the ShapeEntities list it calls the insert / update method for the SingleShapeEntity on the server.
I don’t really want this. I would rather it be something like this,
[EnableClientAccess]
public class ShapeEntity
{
[Key]
public int Id { get; set; }
public IEnumerable<SingleShapeEntity> ShapeEntities { get; set; }
}
But what happens when I do this is the ShapeEntities doesn’t end up being compiled into the client side entity.
Another point as to why I want to do this overall is that I need to be able to operate on the ShapeEntities list on the server as a whole, and at the moment the insert / update method gets called on the server with each SingleShapeEntity item one after the other.
I had to use a work around, I defined an insert method for the SingleShapeMethod on the server which did nothing, like this,
This was called for each SingleShapeEntity that I added to the ShapeEntities enumerable. I didn’t want to deal with them in this method because I need to deal with all of the info at once.
I then had to define the ShapeEntity like this,
When I updated the ShapeEntities I had to set the Updated field to DateTime.Now so that this would trigger an update method to be called on the server,
Without having the Updated field RIA services doesn’t consider the ShapeEntity to have updated and the server update method is not called. When you update the ShapeEntities RIA treats that as an update to the child entities only, not the parent.
Not the best solution, but it works.