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. Questions about saving objects and databases

Questions about saving objects and databases

Scheduled Pinned Locked Moved C#
csharpquestionjavadatabaselinq
4 Posts 3 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.
  • L Offline
    L Offline
    larsp777
    wrote on last edited by
    #1

    Hi! I am renewing a program I made in a university-class in Java. The program is a library system where you can save books as objects, customer as objects and then make a loan. In the old program we saved to disc in a binary-file. How would you do it in C#? I also been thinking about LINQ (which I don´t know very much about), is that and alternative? I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

    K J 2 Replies Last reply
    0
    • L larsp777

      Hi! I am renewing a program I made in a university-class in Java. The program is a library system where you can save books as objects, customer as objects and then make a loan. In the old program we saved to disc in a binary-file. How would you do it in C#? I also been thinking about LINQ (which I don´t know very much about), is that and alternative? I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      larsp777 wrote:

      In the old program we saved to disc in a binary-file.
       
      How would you do it in C#?

      The direct "translation" is .net serialization[^]. You don't need to use the binary formatter described, there is an XML one too (and a SOAP one, but the isn't useful in this context) or you could write your own. Note that it (the binary one) almost certainly won't deserialize the Java files properly. Personally, I wouldn't store anything "complicted" (say with relations or mutliple rows) this way unless I had really good reasons to. You mention LINQ, "LINQ to SQL" and "Entity Framework" are good ways of persisting data and are similar to eachother. You should Google these. A third (non-Microsofty) option is NHibernate, it has similarities to the Entity Framework, but comes with the added advantage, from your point of view, that there is a Java Equivalent ("Hibernate") so by learning one, you learn the Java version (mod any documented differences).

      larsp777 wrote:

      I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

      If I understand you correctly, I'd always go for proper relational design, but that doesn't mean you lose good OO at all. The Entity Framework pretty much expects proper relational design (if you design the DB first, it creates well normalised Schema from an OO model if you start with the model first). NHibernate works better under a properly normalised DB too, but is more forgiving of mismatches between the OO and the DB. That said the same things that drive good OO desgin tend to drive DB schemas: A type is pretty much a table, a property to a simple type pretty much a field and a property to a custom class a relationship to another table. Many-to-One maps to a list property at one end and a single property at the other, Many-to-many has maps to lists at both ends. My advice is to try Entity Framework, starting with the model. Some people have reported performance problems on large data sets, but you can pre-compile LINQ queries and even go the whole hog and use Stored Procs so the perforance is comparable with a little work and you gain more than you lose IMO.

      L 1 Reply Last reply
      0
      • K Keith Barrow

        larsp777 wrote:

        In the old program we saved to disc in a binary-file.
         
        How would you do it in C#?

        The direct "translation" is .net serialization[^]. You don't need to use the binary formatter described, there is an XML one too (and a SOAP one, but the isn't useful in this context) or you could write your own. Note that it (the binary one) almost certainly won't deserialize the Java files properly. Personally, I wouldn't store anything "complicted" (say with relations or mutliple rows) this way unless I had really good reasons to. You mention LINQ, "LINQ to SQL" and "Entity Framework" are good ways of persisting data and are similar to eachother. You should Google these. A third (non-Microsofty) option is NHibernate, it has similarities to the Entity Framework, but comes with the added advantage, from your point of view, that there is a Java Equivalent ("Hibernate") so by learning one, you learn the Java version (mod any documented differences).

        larsp777 wrote:

        I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

        If I understand you correctly, I'd always go for proper relational design, but that doesn't mean you lose good OO at all. The Entity Framework pretty much expects proper relational design (if you design the DB first, it creates well normalised Schema from an OO model if you start with the model first). NHibernate works better under a properly normalised DB too, but is more forgiving of mismatches between the OO and the DB. That said the same things that drive good OO desgin tend to drive DB schemas: A type is pretty much a table, a property to a simple type pretty much a field and a property to a custom class a relationship to another table. Many-to-One maps to a list property at one end and a single property at the other, Many-to-many has maps to lists at both ends. My advice is to try Entity Framework, starting with the model. Some people have reported performance problems on large data sets, but you can pre-compile LINQ queries and even go the whole hog and use Stored Procs so the perforance is comparable with a little work and you gain more than you lose IMO.

        L Offline
        L Offline
        larsp777
        wrote on last edited by
        #3

        Thanks! The course we took in university was alot about OOP. So that was probably the reason we did it this way, to learn OOP.

        1 Reply Last reply
        0
        • L larsp777

          Hi! I am renewing a program I made in a university-class in Java. The program is a library system where you can save books as objects, customer as objects and then make a loan. In the old program we saved to disc in a binary-file. How would you do it in C#? I also been thinking about LINQ (which I don´t know very much about), is that and alternative? I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          larsp777 wrote:

          I final question is if It is a good design or if it would have been better to man a traditional relationship database with no objects.

          Depends what you really mean. If you really want to store a binary image of a book into a database then you have two choices 1. Store it as a blob 2. Store it as a file with a link reference in the database. However if you want to store information about a book, then you should be using a relational database.

          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