Linq-to-SQL 实体不明?请帮忙?
在开发服务时,我在理解一些架构原则方面遇到了一些困难。如果您调用 WCF 服务,它会向客户端返回一个项目集合(Orders)(这些是由 LINQ-to-SQL 实体数据组成的自定义类),并且每个项目都有一个项目集合(OrderItems) (一对多)也由相同的 LINQ-to-SQL 上下文组成。如果我再次调用服务并请求特定的 OrderItem 并在客户端修改其详细信息,那么第一个 Items 集合如何意识到其中一个订单 OrderItem 已从客户端更改。我采用的方法是,在更改 OrderItem 时,我通过 LINQ-to-SQL 命令将 OrderItem 对象发送到 WCF 服务进行存储,但为了更新客户端首先调用的集合,我使用 IList 接口来搜索和替换该对象的每个实例。订单项目。另外,为每个项目订阅 PropertyChanged 事件可以提供一些控制。这确实存在某些明显的限制,但是如何通过管理服务本身更改的所有数据来“更正确”地解决这一问题......ORM?静态类?如果这个问题太难回答,也许我可以通过一些链接甚至聊天组来讨论这个问题,因为我知道该网站适合快速问答类型的主题,而不是指导性的教程讨论。
还是谢谢大家了。
克里斯·利奇
I’m having a little bit of difficulty understanding some architectural principles when developing a service. If you make a call to a WCF service and it returns a collection of items(Orders) (which are custom made classes made up From LINQ-to-SQL entity data) to a client and each item has a collection of items(OrderItems) (one-to-many) that are also made up from the same LINQ-to-SQL context. If I make another call to the service and request a particular OrderItem and modify its details on the client side, how then does the first collection of Items realise that one of its Orders OrderItem has changed from the client side. I am taking the approach of when changing the OrderItem I send the OrderItem object to the WCF service for storage via LINQ-to-SQL commands but to update the collection that the client first called I use IList interface to search and replace each instance of the OrderItem. Also subscribing each item to the PropertyChanged event give some control. This does work with certain obvious limitations but how would one 'more correctly' approach this by perhaps managing all of the data changing from the service itself.. ORM? static classes? If this is too difficult question to answer, perhaps some link or even chat group that I can discuss this as I understand that this site is geared for quick Q/A type topics rather than guided tutorial discussions.
Thanks all the same.
Chris Leach
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有多个客户端同时更改相同的数据,那么最终您的系统必须实现某种并发控制。从广义上讲,这将分为两类之一:悲观或乐观。
就您而言,听起来您正在冒险走上乐观的路线,任何人都可以通过服务访问资源 - 它不会被锁定或独占访问。这意味着最终您需要检测并解决当一个客户端在另一个客户端之前更改数据时会出现的冲突。
您似乎描述的第二个体系结构要求是在客户端之间同步更改的某种方式。这是一个非常困难的问题。一种方法是构建某种发布/订阅系统,在客户端从服务检索某些资源后,它还订阅以获取资源更改的更新。您可以通过基于推或拉的方式执行此操作(拉可能更简单,即只需轮询更改)。
从根本上讲,您正在尝试解决一个相当复杂的问题,但这也是软件中经常出现的问题。
If you have multiple clients changing the same data at the same time, at the end of the day you system must implement some sort of Concurrency Control. Broadly thats going to fall into one of two categories: pessimistic or optimistic.
In your case it sounds like you are venturing down the optimistic route, whereby anyone can access the resource via the service - it does not get locked or accessed exclusively. What that means is ultimately you need to detect and resolve conflicts that will arise when one client changes the data before another.
The second architectural requirement you seem to be describing is some way to synchronize changes between clients. This is a very difficult problem. One way is to build some sort of publish/subscribe system whereby, after a client retrieves some resources from the service, it also subscribes to get updates to changes to resource. You can do this either in a push or pull based fashion (pull is probably simpler, i.e. just poll for changes).
Fundamentally you are trying to solve a reasonably complex problem, but its also one which pops up quite frequently in software.