通过sqldatareader从数据库中获取相关数据并推送到ViewModel/ViewModelCollections中
假设我有以下 3 个实体:Customer、Order、Product,它们在视图中与 CustomerOrderProductViewModel.cs 进行交互:
我有几个控件,如列表框、数据网格等。在我的视图中显示这些实体。
这些实体应以急切加载的方式获取。这意味着我的 DAL 中有 3 个 sqldatareader。每个sqldatareader从表Customer、Product、Order读取数据。我现在必须考虑的问题 如何将订单添加到产品中并将产品添加到客户列表中?将3个for循环中的所有相关数据相互读取?以及如何将相关数据放入我的 VMCollections 中,以便主详细信息保持完整。
MVVM 纯粹主义者和 alpha 极客对这个话题非常沉默。
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View with the CustomerOrderProductViewModel.cs:
I have several controls like listbox,datagrid,etc.. to display those entities in my View.
Those Entities shall be fetched sort of eager loading. That would mean I have 3 sqldatareader in my DAL. Each sqldatareader read data from table Customer,Product,Order. What I have to consider now How do I get the Orders into the Products and the Products into the Customers List ? Read every related data in 3 for-loops into each other? And how do I get that releated data into my VMCollections so the Master Detail stays intact.
The MVVM purists and alpha geeks are very silent about that topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您在处理 DataReader 和要复制的对象的业务对象上设置了构造函数,则可以使用 LINQ 来实现此目的。虽然,我对你的查询的结构有点困惑,但我认为这就是你所说的。
You can use LINQ for this assuming you have constructors setup on your Business objects that handles a DataReader and an object to copy. Although, I'm a little confused about the structure of your query, but I think this is what your saying.