C in CRUD for Silverlight The C in CRUD Silverlight:


Create new Silverlight business application "CRUD"
Add ADO.NET Entity Data Model to CRUD.web
Select the db, the tables, build the project
Add Domain Service Class to CRUD.web
Select the tables and also select the allow editing option for the table "tname"
Build the project
Keep two textboxes "ID" and "NAME" on MainPage.xaml
Keep a button "SAVE NEW RECORD" on MainPage.xaml
Build
Add the following code

Partial Public Class MainPage
    Inherits UserControl

    Dim dserv As New DomainService1

//default methods generated
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'declare a table object
        Dim table As New tname
        'assign values to fields
        table.ID = TextBox1.Text
        table.NAME = TextBox2.Text
        'add table object entity
        dserv.tnames.Add(table)
        'submit the changes, to make it permenant in the db
        dserv.SubmitChanges()
    End Sub

Record inserted


Is this the easiest way for having no side effects to add a new record? Is this the optimal way to add a new record?
I don't think it's best-practice to put any logic that isn't strictly presentation-specific directly into a code-behind event handler like this, let alone that a UserControl knows anything about any DomainService1 object.

If you're shooting for best-practices, you need to look into the Model-View-ViewModel pattern; it's not the job of any UI component to perform any kind of business or data logic.