开发者

Concurrency with a custom DomainService

I have created a class that inherits for DomainService and have a Silverlight app that uses System.ServiceModel.DomainServices.Client to get a DomainContext. I have also created POCO DataContracts that are used in the DomainServices's Query, Update, Insert, and Delete methods. I also have a ViewModel that executes all the LoadOperations. And now I'm at the part of my app where I want to add new Entities to the generated EntitySets but am unsure about what's going to happen when one user creates new and sets the Key value; all while another user creates a similar entity with the same Key value.

I have seen in the documentation that an ObjectContext 开发者_JS百科is used, but in my situation I was not able to use the EntityFramework model generator. So I had to create my datacontracts by hand.

So I guess my question is, is there any way I can force other silverlight apps to update on database change?


When you make a Save operation to your DomainContext, depending on the load behavior, it will automatically refresh.

TicketContext.Load(TicketContext.GetTicketByIdQuery(ticketId),
                                      LoadBehavior.RefreshCurrent,
                                      x =>
                                        {
                                          Ticket = x.Entities.First();
                                          Ticket.Load();
                                          ((IChangeTracking) TicketContext.EntityContainer).AcceptChanges();
                                        }, null);

Here I've set the LoadBehavior to RefreshCurrent. When you make a save, RIA will send the entity back across the wire to the client and merge the changes with the entity already cached on your client side context. I don't know if that quite answers your question or not however.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜