开发者

ObservableCollection(ReadOnly) to editable

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 typic开发者_JS百科al 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!


Try this.

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜