Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Good Practices: DataContexts and BO's

Good Practices: DataContexts and BO's

Scheduled Pinned Locked Moved LINQ
csharpcssdatabasewinformslinq
2 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    I've just nearly finished my first LINQ to SQL winforms application, and I'm quite impressed with how the generated BO's work well with DataGridView etc. The application is a simple invoicing application, allowing grid based maintenance of a product list, grid and detail maintenance of customers, and a detail based form for capturing new invoices, with a line items child grid. I'm curious as to good practices for editing single items in details forms, creating new objects etc. First I passed the selected BO to the details form, but then I had changes reflecting immediately in the grid. Now I pass only the BO ID, and use a new DataContext to load another copy of the object in the details form. This way, changes are only persisted when the user invokes a Save command on the details form. To create a new invoice, I create a new Invoice instance and call InsertOnSubmit with it, then I present it for editing, and when done, I call SubmitChanges to insert the invoice.

    J 1 Reply Last reply
    0
    • B Brady Kelly

      I've just nearly finished my first LINQ to SQL winforms application, and I'm quite impressed with how the generated BO's work well with DataGridView etc. The application is a simple invoicing application, allowing grid based maintenance of a product list, grid and detail maintenance of customers, and a detail based form for capturing new invoices, with a line items child grid. I'm curious as to good practices for editing single items in details forms, creating new objects etc. First I passed the selected BO to the details form, but then I had changes reflecting immediately in the grid. Now I pass only the BO ID, and use a new DataContext to load another copy of the object in the details form. This way, changes are only persisted when the user invokes a Save command on the details form. To create a new invoice, I create a new Invoice instance and call InsertOnSubmit with it, then I present it for editing, and when done, I call SubmitChanges to insert the invoice.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Brady, the way you're doing it sounds reasonable. Another approach may be to modify your BO to support a transaction: when your details form opens up, call BO.BeginTransaction. When the user clicks save, commit the transaction. If not, rollback the transaction. I'm sure there are a number of ways to do this. I don't know whether a transaction approach is superior to your BO copy approach.

      Life, family, faith: Give me a visit. From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?" Judah Himango

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups