Quantcast
Viewing all articles
Browse latest Browse all 7205

How to implement CRUD operations when WcfInstantFeedbackDataSource or WcfServerModeDataSource is used

This example shows how to use WcfInstantFeedbackDataSource or WcfServerModeDataSource with DXGrid, and how to implement CRUD operations (e.g., add, remove, edit) in your application via special behavior.
The test sample requires the SQL Express service to be installed on your machine.

We have created the WCFServerModeCRUDBehavior and WCFInstantModeCRUDBehavior attached behaviors for GridControl. For instance:

[XAML]
<dxg:GridControl><i:Interaction.Behaviors><crud:WCFServerModeCRUDBehavior...><crud:WCFServerModeCRUDBehavior.DataSource/><dxsm:LinqServerModeDataSource.../></crud:WCFServerModeCRUDBehavior.DataSource></crud:WCFServerModeCRUDBehavior></i:Interaction.Behaviors></dxg:GridControl>

 

The WCFServerModeCRUDBehavior and WCFInstantModeCRUDBehavior classes contain the NewRowForm and EditRowForm properties to provide the "Add Row" and "Edit Row" actions. With these properties, you can create the Add and Edit forms according to your requirements:

[XML]
<DataTemplatex:Key="EditRecordTemplate">    <StackPanelMargin="8"MinWidth="200">        <Grid>            <Grid.ColumnDefinitions>                <ColumnDefinition/>                <ColumnDefinition/>            </Grid.ColumnDefinitions>            <Grid.RowDefinitions>                <RowDefinition/>                <RowDefinition/>            </Grid.RowDefinitions>            <TextBlockText="ID:"VerticalAlignment="Center"Grid.Row="0"Grid.Column="0"Margin="0,0,6,4"/>            <dxe:TextEditx:Name="txtID"Grid.Row="0"Grid.Column="1"EditValue="{Binding Path=Id, Mode=TwoWay}"Margin="0,0,0,4"/>            <TextBlockText="Name:"VerticalAlignment="Center"Grid.Row="1"Grid.Column="0"Margin="0,0,6,4"/>            <dxe:TextEditx:Name="txtCompany"Grid.Row="1"Grid.Column="1"EditValue="{Binding Path=Name, Mode=TwoWay}"Margin="0,0,0,4"/>        </Grid>    </StackPanel></DataTemplate><crud:WCFServerModeCRUDBehaviorNewRowForm="{StaticResource ResourceKey=EditRecordTemplate}"EditRowForm="{StaticResource ResourceKey=EditRecordTemplate}"/>

This Behavior classes require the following information from your data model:
- EntityObjectType - the type of rows;
- DataServiceContext - an object of the DataServiceContext type;
- PropertiesList - the table columns' list;
- PrimaryKey - the primary key of the database table;
- DataSource - an object of the WcfInstantFeedbackDataSource or WcfServerModeDataSource type.

[XML]
<dxg:GridControl><i:Interaction.Behaviors><crud:WCFInstantModeCRUDBehaviorEntityObjectType="{x:Type sr:Item}"DataSource="{Binding ElementName=wcfInstantSource}"DataServiceContext="{Binding DataSource.DataServiceContext, RelativeSource={RelativeSource Self}}"/></i:Interaction.Behaviors></dxg:GridControl>
[C#]
helper.PropertiesList.Add("Id");helper.PropertiesList.Add("Name");

See the WcfInstantFeedbackDataSource and WcfServerModeDataSource classes to learn more about WcfInstantFeedbackDataSource and WcfServerModeDataSource .

Behavior class descendants support the following commands: NewRowCommand, RemoveRowCommand, EditRowCommand. You can bind your interaction controls with these commands with ease. For instance:

[XML]
<crud:WCFServerModeCRUDBehaviorx:Name="helper"/><StackPanelGrid.Row="1"Orientation="Horizontal"HorizontalAlignment="Center"><ButtonHeight="22"Width="60"Command="{Binding Path=NewRowCommand, ElementName=helper}">Add</Button><ButtonHeight="22"Width="60"Command="{Binding Path=RemoveRowCommand, ElementName=helper}"Margin="6,0,6,0">Remove</Button><ButtonHeight="22"Width="60"Command="{Binding Path=EditRowCommand, ElementName=helper}">Edit</Button></StackPanel>

By default, the WCFServerModeCRUDBehavior and WCFInstantModeCRUDBehavior solutions support the following end-user interaction capabilities:
1. An end-user can edit selected row values by double-clicking on a grid row or by pressing the Enter key if the AllowKeyDownActions property is True.
2. An end-user can remove selected rows via the Delete key press if the AllowKeyDownActions property is True.
3. An end-user can add new rows, remove and edit them via the NewRowCommand, RemoveRowCommand, and EditRowCommand commands.

Question Comments

Added By: Claire N Streb at: 8/12/2012 9:03:43 AM    

Just in case anyone else experiences this problem, I received this error when trying to attach the provided Database.mdf file to the SQL Server database: The database '[snip]\DATABASE.MDF' cannot be opened because it is version 661. This server supports version 655 and earlier. A downgrade path is not supported. To fix it, I opened the model, generated the database from the model, added the database into SQL Server under a different name, excluded Database.mdf from the solution, added the newly created database to the solution, and changed the web.config file.


Viewing all articles
Browse latest Browse all 7205

Trending Articles