ObservableCollection(ReadOnly) 改为可编辑

发布于 2024-11-04 06:53:29 字数 750 浏览 3 评论 0原文

我有一个 SL4 WCF / RIA LOB 正在学习。我有一个 SQL 视图,以 IQueryable 形式返回当前库存。由于它是一个 SQL 视图,因此它被标记为只读,这正是我想要的/不对数据库进行任何更改。

在前端(视图),我想用信息填充 DataGrid,但允许在用户选择可用库存时对其进行编辑。在我看来,DataGrid 的绑定应该是我可以在内存中操作的不同集合。

目前,我有一个典型的 DDS 从后面拉取查询:

<riaControls:DomainDataSource AutoLoad="True" LoadedData="qryInventoryDds_LoadedData" 
                                  Name="qryInventoryDds" QueryName="GetQryInventoriesQuery" >
        <riaControls:DomainDataSource.DomainContext>
            <my:DomainService1 />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>

如果有人可以指导我如何“复制”此 e.Entities 等,以便我可以操作它然后绑定它,我将非常感激。

我搜索了几天,确实找不到一些好的例子。

非常感谢!

I have a SL4 WCF / RIA LOB am learning with. I have a SQL view returning current inventory as an IQueryable. As it is a SQL view it is marked as read-only which is what I want / no changes to the DB.

At the front end (view), I want to populate a DataGrid with the information, but allow it to be editable as the user picks available inventory. It seems to me the binding of the DataGrid should be to a different collection that I can manipulate in memory.

Currently I have a typical DDS pulling the query from the back:

<riaControls:DomainDataSource AutoLoad="True" LoadedData="qryInventoryDds_LoadedData" 
                                  Name="qryInventoryDds" QueryName="GetQryInventoriesQuery" >
        <riaControls:DomainDataSource.DomainContext>
            <my:DomainService1 />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>

If someone can make give me direction on how I should "copy" this e.Entities or such so I can manipulate it and then bind it I would appreciate it greatly.

I've search for a couple days and really can't find some good examples.

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法唧唧 2024-11-11 06:53:29

试试这个。

<data:DataGrid x:Name="myDataGrid" ItemsSource="{Binding ElementName=qryInventoryDds, Path=Data}" RowDetailsVisibilityMode="VisibleWhenSelected">

Try this.

<data:DataGrid x:Name="myDataGrid" ItemsSource="{Binding ElementName=qryInventoryDds, Path=Data}" RowDetailsVisibilityMode="VisibleWhenSelected">
不即不离 2024-11-11 06:53:29

我所做的是迭代返回的集合,创建一个不属于域上下文的新的 ObservableCollection。我相信这被称为深层复制。

似乎没有方法可以“轻松”从 SQL 视图检索可编辑集合,因为 VS 将所有业务对象属性标记为主键。我读过/尝试过一些策略,例如在 SQL 视图中标记所有字段 COALESCE(propery, null),但这对我不起作用。另外,有些人尝试编辑底层模型 XML,但这必须在每次更改视图时完成,这是非常有问题的。

如果有人知道更好的解决方案,我洗耳恭听。

谢谢。

WHat I've done is iterate through the returned collection creating a new ObservableCollection that is not part of the domaincontext. I believe this is known as a deep copy.

It seems that there is no method to "easily" retrieve an editable collection from a SQL view as VS markes all business object properties as primary keys. There are some strategies I've read / tried like marking all fields COALESCE(propery, null) in the SQL view but this did not work for me. Also some try and edit the underlying model XML but that would have to be done on each alteration of the view which is highly problematic.

If anyone knows of a better solution, I'm all ears.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文