I have recently been doing some work with Windows Azure Mobile Services, and have been very impressed by how easy it is to develop against. I have a blog in progress about populating databases, but after embarking on a third application using WAMS, I realised that a lot of the code was repetitive and could be automated.
Every WAMS project will need to define the tables, and probably also write data to those tables. So, I decided to take a few hours out to write something to help developers (and ourselves) take advantage of WAMS. The result is APPA Wams, which will:-
a) Generate table definitions for all tables in a database
b) Generate 'insert' statements for all tables in a database
c) Generate skeleton 'read' statements for all tables in a database
d) Generate view models for all tables in the database
This should save developers quite a bit of time when developing for WAMS. You simply need to provide the parameters for connecting to your database, choose an output file, and a namespace, and APPA Wams does the rest. Your database can be local, on a server or an Azure database.
When the program finishes, all you need do is add 'Database.cs' and the view model files to your development project. The view model files are named from the table names, for example UsersItemViewModel.cs and UsersMainViewModel.cs.
The table definitions code produced is:-
and all the tables are defined. There are skeleton processes for writing to each table in the database - all you need to do is supply the data. The code is:-
There are procedures for reading from tables. The procedures show how to read from tables with selection criteria, and populate the view models we created. It just needs tweaking for your own use.
Finally, there will be view models created for each table in the database, named according to the tables, for example UsersItemViewModel.cs and UsersMainViewModel.cs. The item view model code produced is:-
Including the implementation of INotifyPropertyChanged
and the 'Main' view model code:-
We also produce a file, based on your name space(SalesFile_CodeForApp.xaml.cs in this case) containing the declarations of the view models. This can be cut and pasted into App.xaml.cs so that your view models are available throughout your application.
The code produced by APPA Wams should work equally well for Windows Phone and Windows Store projects.
We hope this will prove to be a useful tool for developers. It is supplied 'as is', but you can mail email@example.com with any suggestions for improvements (or errors). You can download APPA Wams here.
Thanks to Mike Taulty whose talk to the Windows Phone User Group (North West) a few weeks ago stimulated my interest in WAMS, and gave me some help along the way with my initial project.
Mar 23 2013, 04:40 PM