3
\$\begingroup\$

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?

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Seems like the OP is more looking for what's easiest though. \$\endgroup\$ – Simon Forsberg Nov 20 '13 at 14:26
  • \$\begingroup\$ @Simon true, but the post is also tagged [best-practices] \$\endgroup\$ – Mathieu Guindon Nov 20 '13 at 15:39
  • \$\begingroup\$ That's true, I would give you an upvote but I'm out of them for the time being (as usual). \$\endgroup\$ – Simon Forsberg Nov 20 '13 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.