- Add a new Component Class to the project using the Add New Item wizard and name it something, I named mine "DataService"
- Open the DataService component in the designer and add a BinMessage, a LinqRemoteDataAdapter, a client channel (ipHttpClientChannel in my case), Bin2DataStreamer and a RemoteService on the designer surface and wire them appropriately
- Since this is a simple exercise I made the Modifier for the LinqRemoteDataAdapter on the DataService component public so I could access it easily. For a larger project you'll probably want to do this in a more OOP manner.
- Select the LinqRemoteDataAdapter's Smart Tag and chose the "Create DA LINQ Classes" option. Be sure to have your server running when you run the wizard or you'll get an error because it can't connect. Afterwards you should have a TableDefinitions.cs file automatically added to the WPF client's project.  

- Right click on your WPF project and use the Add Existing Item wizard to insert a shortcut to the DataAbstract Server's _Intf file. Be sure to use the drop down menu and select "Add As Link".

- Add a DataGrid and a couple buttons to the main Window. One button will be for opening the query and one for updating the query after any changes you make using DALinq DataBinding.
- Add a couple variables to use and instantiate our DataService so we can get the data like this:
private IQueryable<Customers> _list;
private DataService _dataService;
public Window1()
{
InitializeComponent();
_dataService = new DataService();
} - Add the following code behind our query button:
private void btnOpenQuery_Click(object sender, RoutedEventArgs e)
{
_list = from cust in _data.linqRemoteDataAdapter.GetTable<Customers>()
where (cust.City == "México D.F.")
orderby cust.ContactName ascending
select cust;
dataGrid1.AutoGenerateColumns = true;
dataGrid1.ItemsSource = null;
dataGrid1.ItemsSource = _list.ToDABindingList();
} - We'll add this DALinq DataBinding code behind our update button:
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
((DABindingList<Customers>)dataGrid1.ItemsSource).SaveChanges(_dataService.linqRemoteDataAdapter);
_dataService.linqRemoteDataAdapter.ApplyChanges();
}
The steps look like more effort than they really are. Particularly once you get comfortable with the framework. Since I'm still somewhat new to WPF that's where I spent most of my time learning new things. In the end we have a nice little form that opens our LINQ query and updates it for us automagically. The end result looks like this:

This test project can be downloaded here.
About The Author
Ron Grove draws on over ten years of training, network administration and development experience. He loves to work with new technology and see how that technology can be best utilized by his clients. You can find him through his company Evanoah, LLC and his LinkedIn profile is here.
0 comments:
Post a Comment