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. C#
  4. Design Question - Business Object Layer and Data Access

Design Question - Business Object Layer and Data Access

Scheduled Pinned Locked Moved C#
databasetutorialquestioncssdesign
4 Posts 4 Posters 0 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.
  • M Offline
    M Offline
    matthias s 0
    wrote on last edited by
    #1

    Hi, I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields. 1. Company (ID, Name, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip) (Those two obviously have a relationship) Now I'd go and create an object called Company and one for the AddresseInfo. AddresseInfo would be a public member of Company. Usually you'll have more than one company to manage so I create a strongly typed collection called CompanyCollection. Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollection take care of it (which IMHO seems a lot less coding to me on first sight)? 2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up. The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? Here is some additional information which I feel might be usefull: a. The amount of BusinessObject loaded from the Database is never really huge. Say a maximum of 2000 objects. b. BusinessObjects might contain collections of other BusinessObjects, e.g. the Company object will contain a EmployeeCollection. c. The amount of different BusinessObjects will probably not exceed 20. d. Performance issues are not a knock out criteria. e. The solution that I'm after is simple to code and maintain. I don't actually want to create a huge Framework with hundrets of classes which provide for unlimited scalability and the forth. We are talking about an application which is used by 10 people and new versions can be installed at any time if required. I hope someone can give me some advice on how to design this properly. Thanks in advance, Matthias

    S H S 3 Replies Last reply
    0
    • M matthias s 0

      Hi, I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields. 1. Company (ID, Name, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip) (Those two obviously have a relationship) Now I'd go and create an object called Company and one for the AddresseInfo. AddresseInfo would be a public member of Company. Usually you'll have more than one company to manage so I create a strongly typed collection called CompanyCollection. Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollection take care of it (which IMHO seems a lot less coding to me on first sight)? 2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up. The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? Here is some additional information which I feel might be usefull: a. The amount of BusinessObject loaded from the Database is never really huge. Say a maximum of 2000 objects. b. BusinessObjects might contain collections of other BusinessObjects, e.g. the Company object will contain a EmployeeCollection. c. The amount of different BusinessObjects will probably not exceed 20. d. Performance issues are not a knock out criteria. e. The solution that I'm after is simple to code and maintain. I don't actually want to create a huge Framework with hundrets of classes which provide for unlimited scalability and the forth. We are talking about an application which is used by 10 people and new versions can be installed at any time if required. I hope someone can give me some advice on how to design this properly. Thanks in advance, Matthias

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      hi, Good question. See i can help some part of your problem. Say Mathias Wrote: The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? So some cases user may changes few document against a list. Here you can use indexcer to get proper instance of object from your collection which hold real updation. I think this is the better way to know and choose a perticular record which have updation. I already faced the same situation that you mentioned in your queary. Here i applied indexcer to tackle my issue. And it is pretty fast than checking all objects in collection. Sreejith Nair

      1 Reply Last reply
      0
      • M matthias s 0

        Hi, I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields. 1. Company (ID, Name, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip) (Those two obviously have a relationship) Now I'd go and create an object called Company and one for the AddresseInfo. AddresseInfo would be a public member of Company. Usually you'll have more than one company to manage so I create a strongly typed collection called CompanyCollection. Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollection take care of it (which IMHO seems a lot less coding to me on first sight)? 2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up. The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? Here is some additional information which I feel might be usefull: a. The amount of BusinessObject loaded from the Database is never really huge. Say a maximum of 2000 objects. b. BusinessObjects might contain collections of other BusinessObjects, e.g. the Company object will contain a EmployeeCollection. c. The amount of different BusinessObjects will probably not exceed 20. d. Performance issues are not a knock out criteria. e. The solution that I'm after is simple to code and maintain. I don't actually want to create a huge Framework with hundrets of classes which provide for unlimited scalability and the forth. We are talking about an application which is used by 10 people and new versions can be installed at any time if required. I hope someone can give me some advice on how to design this properly. Thanks in advance, Matthias

        H Offline
        H Offline
        hatim_ali
        wrote on last edited by
        #3

        You Wrote: The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? In My Opinion: Save one on one basis that is "Save" can be done on open screens only. When your application user double clicks the company tree view a "document window" with company details with a save button will be presented to user. If the user want to persist the chages, he'll hit save and your code will invoke save inteface on the business object. This will save you scanning all objects in collection and will also save you from maintining that which objects have been changed. Some other suggestions: Creating objects for all companies may not be an optimal idea. Only fetch company names and Identification info (IDs) from database and render it to tree view. Obviously these objects will be lightweight as no company info is fetched. Now, if your app user selects a company, create a Object of Class Company with all the company details and render it to user. hope it helps, Hatim Ali.

        1 Reply Last reply
        0
        • M matthias s 0

          Hi, I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields. 1. Company (ID, Name, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip) (Those two obviously have a relationship) Now I'd go and create an object called Company and one for the AddresseInfo. AddresseInfo would be a public member of Company. Usually you'll have more than one company to manage so I create a strongly typed collection called CompanyCollection. Now on to the questions: 1. Should each individual object be responsible of loading and saving it's data from and to the database or should the CompanyCollection take care of it (which IMHO seems a lot less coding to me on first sight)? 2. Assumed the Collection takes care of the data-fetching, how should then the data changes whithin the individual objects be handled? What comes in mind is either a IsDirty property of each of the BusinessObjects (Company and AddresseInfo) (which can be checked by the collection) or an event (say DataChanged) to which the collection would hook up. The problem I see with this approach is the following. Say my MDI GUI displays a list of all Companies in a TreeView on the lefthandside. On DoubleClick the selected BusinessObject gets displayed in a new "Document Window" which hosts a PropertyGrid control. Now my user opens 3 Companies and changes the data of all of them. How would I then handle the situation when he only wants to save to of those documents? Here is some additional information which I feel might be usefull: a. The amount of BusinessObject loaded from the Database is never really huge. Say a maximum of 2000 objects. b. BusinessObjects might contain collections of other BusinessObjects, e.g. the Company object will contain a EmployeeCollection. c. The amount of different BusinessObjects will probably not exceed 20. d. Performance issues are not a knock out criteria. e. The solution that I'm after is simple to code and maintain. I don't actually want to create a huge Framework with hundrets of classes which provide for unlimited scalability and the forth. We are talking about an application which is used by 10 people and new versions can be installed at any time if required. I hope someone can give me some advice on how to design this properly. Thanks in advance, Matthias

          S Offline
          S Offline
          Serge Lobko Lobanovsky
          wrote on last edited by
          #4

          Take a look at Martin Fowler's "Patterns of Enterprise Application Architecture" Regards, Serge (Logic Software, Easy Projects .NET site)

          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