Geeks With Blogs
Here I Dreamt I Was an Architect...
| Home |

Thanks to all of you who attended my session at STL Day of Dotnet.  Hopefully you found it useful.  You may find a copy of my presentation here:


I hope to create some follow up blog entries on this topic but in the meantime, you may download the sample project here


I have also included the script I used to build the demo.


    1. New Project - Silverlight Business Application AdventureWorksHR @ C:\Code Projects\DayOfDotNet2010\
    1. Build and Run. Explain what is there by default.
    2. In .Web Add New Item.
      1. From Data Category select ADO.Net Entity Model
      1. Name the file AWHRModel.edmx
      1. Leave Generate form Database Selected and Click Next
      1. Create a new Connection
        1. Server: SCS10L2259\SCS10L2259
        1. Windows Authentication
        1. Database: AdventureWorks
      1. Save entity connection settings in Web.config as AdventureWorksHREntities
      1. Choose All (Person) and (HumanResources) Tables
      1. Change Name to AdventureWorksHRModel
      1. Click Finish
    1. Review AWHRModel.edmx
    2. Build Solution (needed for step 6c)
    1. In .Web, Add New Item
      1. From Web Category select Domain Service Class
      1. Name the File AWHRDomainService.cs
      1. Select AdventureWorksHREntities(Entity Framework)
      1. Select All Entities and Enable Editing (overkill here, in practice you should pick only what you need)
      1. Click OK
    1. Review AWHRDomainService.cs
    1. Navigate to GetEmployees(), change it to: return this.ObjectContext.Employees.Include("Contact");
    1. Navigate to: AWHRDomainService.metadata.cs (USE CTRL+, and explain its wonderful)
    1. Add Include Attribute to Employee.Contact and add [Include]
    2. Build.
    1. Open up Home.xaml
    1. Delete ScrollViewer and Contents. (Just to clean things up a bit and start with a blank slate)
    1. Add a row to GRID by clicking in blue area on right
    1. Open and Pin Data Sources
    1. Click on Employee Drop Down
      1. Show them Options, including which query it is using by default, if there was more than one then it would show up.
      2. Be sure Datagrid is selected.
      3. Show them list of columns and Options for displaying them.
      1. Turn off everything but
        1. BirthDate
        1. CurrentFlag
        1. EmployeeId
        2. Gender
        1. LoginId
        2. MaritalStatus
        1. SalariedFlag
        1. SickLeaveHours
        1. Title
        1. VacationHours
    1. Drag and Drop Employee onto top Row of Home.xaml
    1. Size it appropriately, fixed left and top, realtive right ans bottom (click on circle)
    1. Build and Run. (notice all our columns are there as expected) READ DONE!
    1. Go back to visual studio, and end debugging
    1. Open Home.xaml(Now let's clean up those columns a bit.)
    1. Click the DataGrid and Open up Properties
    1. Find and Expand Columns Collection
    1. Reorder Columns so they are more Natural
    2. Change employeeIDColumn header to Employee Number
    1. Change loginIDColumn Layout.Width to SizeToCells
    1. Change titleColumn Layout.Width to SizeToCells
    1. Build an Run. (there that looks a bit better)
    2. Return To Visual Studio, Stop Debugging and Open Home.xaml
    3. Open up ToolBox, Find Scrollviewer, Drag it onto row 2 of Home.xaml
    1. Size it appropriately, Change Vertical and Horizontal alignment to Top and Left
    1. Open Data Sources Window and Expand Employee.
    1. From the Drop Down, select Details
    1. Change Contact to Details View
    1. Drag Employee inside Scrollviewer on Home.xaml and size appropriately.
    2. Build and RUN.
    3. Return to Visual Studio, End Debugging and open up Home.xaml
    1. Add a middle Row to the Root Grid.
    2. Open Toolbox and Drag a StackPanel to middle row.
    1. Size appropriately and change Orientation to Horizontal.
    1. Drag on 4 buttons into StackPanel
    2. Select all 4 using Ctrl+Click and change
      1. Width=100
      1. Margin=10,0,10,0
    1. Open up Properties For Button 1 and Change
      1. Name: SaveChangesButton (click next to Button at top of properties
      1. Content: Save Changes
    1. Open up Properties For Button 2 and Change
      1. Name: CancelChangesButton (click next to Button at top of properties
      1. Content: Cancel Changes
    1. Open up Properties For Button 3 and Change
      1. Name: AddEmployeeButton (click next to Button at top of properties
      2. Content: Add Employee
    1. Open up Properties For Button 4 and Change
      1. Name: DeleteEmployeeButton (click next to Button at top of properties
      1. Content: Delete Employee
    1. Double Click SaveChangesButton. This Generates a SaveChangesButton_Click event in Home.xaml.cs
    1. Add the following code to SaveChangesButton_Click
      1. employeeDomainDataSource.SubmitChanges();
    1. Return to Home.xaml and double click CancelChangesButton
      1. (Can anyone tell me what to type here?)
      1. employeeDomainDataSource.RejectChanges();
    1. Return to Home.xaml and double click AddEmployeeButton
                Employee emp = new Employee();
                emp.NationalIDNumber = "0";
                emp.ModifiedDate = System.DateTime.Now;
                emp.BirthDate = System.DateTime.Now.AddYears(-21);
                emp.HireDate = System.DateTime.Now;
                emp.Contact = new Contact();
                emp.Contact.rowguid = Guid.NewGuid();
                emp.Contact.ModifiedDate = System.DateTime.Now;
                emp.Contact.PasswordHash = "Hashed";
                emp.Contact.PasswordSalt = "salty";
    1. Return to Home.xaml and double click DeleteEmployeeButton(Note in order to Delete an employee must remove delete trigger on HumanResource.Employee)
       if (System.Windows.Browser.HtmlPage.Window.Confirm("Are you sure? (Note employee will not be deleted until changes are saved.)"))
    1. (Now let's add a smidge of error handling)
      1. Open Home.xaml
      1. Navigate to employeeDomainDataSource
      2. Add SubmittedChanges event
      1. private void employeeDomainDataSource_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
                StringBuilder sb = new StringBuilder();
                if (e.HasError)
                foreach (Entity ent in e.EntitiesInError)
                    foreach (ValidationResult verr in ent.ValidationErrors)
                if (e.HasError)
                    System.Windows.MessageBox.Show(sb.ToString(), "Submit Changes Error", 
    1. Build and Run
    1. Test Change
      1. Pick someone change their hours
      1. Submit Changes.
      2. Pick someone new
      3. Change title, Cancel Changes
      4. Refresh page.
      5. Validate Changes.
    1. Test Add Employee
      1. Add New Employee
      1. Fill Out all relevant fields.
      1. Submit Changes.
      2. Refresh
      3. Validate Changes
    1. Test Delete Employee
      1. Delete previously added employee.
      1. Cancel Changes.
      1. Delete previously added employee.
      1. Submit Changes
      1. Refresh and Validate
    1. Return to Visual Studio
    2. Navigate to AWHRDomainService.metadata.cs
    3. Add [RegularExpression("[M,F]")] to Gender Property of Employee
    4. Navigate to Home.xaml
    1. For Cancel and Save buttons, open up Properties, and Create a DataBinding for the IsEnabled Property ElementName=employeeDomainDataSource, Path=HasChanges
    1. Drag a BusyIndicator onto top Row of Home.xaml
    1. Bind IsBusy Property to ElementName=employeeDomainDataSource, Path=IsBusy
    2. Open Assets.Resources.ApplicationStrings.resx and change ApplicationName to AdventureWorks HR System
    1. Build, Run and Test
Posted on Sunday, August 22, 2010 8:40 PM Silverlight , RIA Services , Presentations , STLDODN | Back to top

Comments on this post: Saint Louis Day of DotNet Session- Get Rid of CRUD Faster, Using Silverlight and RIA Services to quickly develop CRUD applications.

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Kyle Shaffar | Powered by: