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. Is strongly typed database code worth it? It's giving me a headache!

Is strongly typed database code worth it? It's giving me a headache!

Scheduled Pinned Locked Moved C#
databasecsharpjavaquestionasp-net
9 Posts 6 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
    MattPenner
    wrote on last edited by
    #1

    OK, I love to learn new and better ways to do things, but this just doesn't seem one of them. I'm originally from the Java camp so I've used straight DB code such as hard coded calls to the database and ORM tools like Hibernate. I've been working in VB for the past 5 years on various projects and have used similar techniques here as well. I am working on a fairly large project and decided to use strongly typed db access such as what is taught in these fairly popular tutorials: http://www.asp.net/learn/data-access/[^] Boy am I getting a headache. It seems to me that the only benefits I get are IntelliSense and compile time checking. IntelliSense wasn't available before strongly typed database code so this is more of a convenience than any real need. Compile time checking is nice but I've already had several errors that are not caught until runtime. These errors largely deal with enforcing constraints when filling a DataTable using a standard DataAdapter. Most of these errors are extremely trivial, do not interfere with my actual code and would never have been brought to my attention without strongly typed db code. So here is what I see as the major negative. I feel like I am getting much more code dependence rather than the current shift towards independence. This project largely works with data from a vendor database. If they ever update their schema (which can be as often as once a week) my app will break, even if they simply change a field from varchar(10) to varchar(12). I'm starting to lean towards either rolling my own db code or using NHibernate again. Also, LINQ seems to be a departure from this strategy as well. Does anyone else have any comments? Have any of you used strongly typed db code on a large project and found it to be indispensable? What am I missing? Thanks! Matt Penner

    J L M O 4 Replies Last reply
    0
    • M MattPenner

      OK, I love to learn new and better ways to do things, but this just doesn't seem one of them. I'm originally from the Java camp so I've used straight DB code such as hard coded calls to the database and ORM tools like Hibernate. I've been working in VB for the past 5 years on various projects and have used similar techniques here as well. I am working on a fairly large project and decided to use strongly typed db access such as what is taught in these fairly popular tutorials: http://www.asp.net/learn/data-access/[^] Boy am I getting a headache. It seems to me that the only benefits I get are IntelliSense and compile time checking. IntelliSense wasn't available before strongly typed database code so this is more of a convenience than any real need. Compile time checking is nice but I've already had several errors that are not caught until runtime. These errors largely deal with enforcing constraints when filling a DataTable using a standard DataAdapter. Most of these errors are extremely trivial, do not interfere with my actual code and would never have been brought to my attention without strongly typed db code. So here is what I see as the major negative. I feel like I am getting much more code dependence rather than the current shift towards independence. This project largely works with data from a vendor database. If they ever update their schema (which can be as often as once a week) my app will break, even if they simply change a field from varchar(10) to varchar(12). I'm starting to lean towards either rolling my own db code or using NHibernate again. Also, LINQ seems to be a departure from this strategy as well. Does anyone else have any comments? Have any of you used strongly typed db code on a large project and found it to be indispensable? What am I missing? Thanks! Matt Penner

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

      We use XPO[^] here at work. We had done it "by hand" previously, and XPO saves us tons of time. That said, it's not a walk in the park. There are still issues, such as the db scheme change breakings (although XPO handles most schema changes automatically OK). Most O/R mappers give you database independence; your code will work with MS SQL Server, MySQL, Oracle, Access, whatever. Overall, I'm certainly glad we have an O/R mapper. It could be better, but it's far, far better than doing it by hand.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      L P 2 Replies Last reply
      0
      • J Judah Gabriel Himango

        We use XPO[^] here at work. We had done it "by hand" previously, and XPO saves us tons of time. That said, it's not a walk in the park. There are still issues, such as the db scheme change breakings (although XPO handles most schema changes automatically OK). Most O/R mappers give you database independence; your code will work with MS SQL Server, MySQL, Oracle, Access, whatever. Overall, I'm certainly glad we have an O/R mapper. It could be better, but it's far, far better than doing it by hand.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Judah Himango wrote:

        It could be better

        Yes it could. As a work around, don't do development that uses databases... actually don't do development that uses data at all.... oh what heck just don't do software development. Hey maybe the circus that's in town could use another clown? ;)

        J 1 Reply Last reply
        0
        • M MattPenner

          OK, I love to learn new and better ways to do things, but this just doesn't seem one of them. I'm originally from the Java camp so I've used straight DB code such as hard coded calls to the database and ORM tools like Hibernate. I've been working in VB for the past 5 years on various projects and have used similar techniques here as well. I am working on a fairly large project and decided to use strongly typed db access such as what is taught in these fairly popular tutorials: http://www.asp.net/learn/data-access/[^] Boy am I getting a headache. It seems to me that the only benefits I get are IntelliSense and compile time checking. IntelliSense wasn't available before strongly typed database code so this is more of a convenience than any real need. Compile time checking is nice but I've already had several errors that are not caught until runtime. These errors largely deal with enforcing constraints when filling a DataTable using a standard DataAdapter. Most of these errors are extremely trivial, do not interfere with my actual code and would never have been brought to my attention without strongly typed db code. So here is what I see as the major negative. I feel like I am getting much more code dependence rather than the current shift towards independence. This project largely works with data from a vendor database. If they ever update their schema (which can be as often as once a week) my app will break, even if they simply change a field from varchar(10) to varchar(12). I'm starting to lean towards either rolling my own db code or using NHibernate again. Also, LINQ seems to be a departure from this strategy as well. Does anyone else have any comments? Have any of you used strongly typed db code on a large project and found it to be indispensable? What am I missing? Thanks! Matt Penner

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          MattPenner wrote:

          What am I missing?

          This requirement of yours seems to stand out... to me anyway.

          MattPenner wrote:

          If they ever update their schema (which can be as often as once a week)

          That seems to be a significant requirement to me. Based on that requirement I would not expect standard database techniques to sufficiently meet that requirement. It might warrant specific custom design to accomplish flexibility and extensibility.

          1 Reply Last reply
          0
          • M MattPenner

            OK, I love to learn new and better ways to do things, but this just doesn't seem one of them. I'm originally from the Java camp so I've used straight DB code such as hard coded calls to the database and ORM tools like Hibernate. I've been working in VB for the past 5 years on various projects and have used similar techniques here as well. I am working on a fairly large project and decided to use strongly typed db access such as what is taught in these fairly popular tutorials: http://www.asp.net/learn/data-access/[^] Boy am I getting a headache. It seems to me that the only benefits I get are IntelliSense and compile time checking. IntelliSense wasn't available before strongly typed database code so this is more of a convenience than any real need. Compile time checking is nice but I've already had several errors that are not caught until runtime. These errors largely deal with enforcing constraints when filling a DataTable using a standard DataAdapter. Most of these errors are extremely trivial, do not interfere with my actual code and would never have been brought to my attention without strongly typed db code. So here is what I see as the major negative. I feel like I am getting much more code dependence rather than the current shift towards independence. This project largely works with data from a vendor database. If they ever update their schema (which can be as often as once a week) my app will break, even if they simply change a field from varchar(10) to varchar(12). I'm starting to lean towards either rolling my own db code or using NHibernate again. Also, LINQ seems to be a departure from this strategy as well. Does anyone else have any comments? Have any of you used strongly typed db code on a large project and found it to be indispensable? What am I missing? Thanks! Matt Penner

            M Offline
            M Offline
            MaxRelaxman
            wrote on last edited by
            #5

            On program startup, you could query the schema for all your tables. Build class to hold information like field names, value types and lengths. Here's some of my code, I'm sure most people here can come up with something more effecient :-D. The tabbing is getting killed but you get the idea. Mine looks something like this namespace DBWrapper { public class FieldInfo { private string strField = string.Empty; private string strType = string.Empty; private int nLen = 0; public string FieldName { get { return strField; } set { strField = value; } } public string FieldType { get { return strType; } set { strType = value; } } public int FieldLen { get { return nLen; } set { nLen = value; } } } public class TableData : List { /// /// Returns a FieldInfo Struct based on the provided field name. /// /// /// null on failure public FieldInfo Get(string strFieldName) { FieldInfo retFieldInfo = new FieldInfo(); foreach (FieldInfo fiInfo in this) { if (string.Compare(fiInfo.FieldName, strFieldName, true) == 0) return fiInfo; } return new FieldInfo(); } } } To get the schema info I use this (I think this is half my code and half somebody elses but it's been so long since I touched it I don't remember) protected bool GetTableSchema(out DataTable dtSchema) { dtSchema = new DataTable(); SqlCommand dbCommand = new SqlCommand(); SqlDataReader dbReader; bool bRetValue; if (!OpenDatabase()) return false; try { dbCommand.CommandText = "SELECT * FROM " + m_strTableName; dbCommand.Connection = m_DBConnection; dbReader = dbCommand.ExecuteReader(CommandBehavior.KeyInfo); dtSchema = dbReader.GetSchemaTable(); bRetValue = true; } catch (Exception ex) { string strErrorMessage = "Error Getting Table Schema " + dbCommand.CommandText + "\r\nMsg: " + ex.Message; #if DEBUG Console.WriteLine(strErrorMessage); #else m_LogHandler.WriteLogLine(strErrorMessage); #endif bRetValue = fal

            1 Reply Last reply
            0
            • J Judah Gabriel Himango

              We use XPO[^] here at work. We had done it "by hand" previously, and XPO saves us tons of time. That said, it's not a walk in the park. There are still issues, such as the db scheme change breakings (although XPO handles most schema changes automatically OK). Most O/R mappers give you database independence; your code will work with MS SQL Server, MySQL, Oracle, Access, whatever. Overall, I'm certainly glad we have an O/R mapper. It could be better, but it's far, far better than doing it by hand.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Yay XPO. I like XPO - even with its quirks.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              1 Reply Last reply
              0
              • L led mike

                Judah Himango wrote:

                It could be better

                Yes it could. As a work around, don't do development that uses databases... actually don't do development that uses data at all.... oh what heck just don't do software development. Hey maybe the circus that's in town could use another clown? ;)

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

                led mike wrote:

                Hey maybe the circus that's in town could use another clown?

                Sorry, I went there last night and took the LAST CLOWN JOB IN TOWN. Ha. Take that, you clown-wannabe. ;)

                Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                L 1 Reply Last reply
                0
                • J Judah Gabriel Himango

                  led mike wrote:

                  Hey maybe the circus that's in town could use another clown?

                  Sorry, I went there last night and took the LAST CLOWN JOB IN TOWN. Ha. Take that, you clown-wannabe. ;)

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  Judah Himango wrote:

                  you clown-wannabe.

                  Not really... I was just clowning around. :laugh:

                  1 Reply Last reply
                  0
                  • M MattPenner

                    OK, I love to learn new and better ways to do things, but this just doesn't seem one of them. I'm originally from the Java camp so I've used straight DB code such as hard coded calls to the database and ORM tools like Hibernate. I've been working in VB for the past 5 years on various projects and have used similar techniques here as well. I am working on a fairly large project and decided to use strongly typed db access such as what is taught in these fairly popular tutorials: http://www.asp.net/learn/data-access/[^] Boy am I getting a headache. It seems to me that the only benefits I get are IntelliSense and compile time checking. IntelliSense wasn't available before strongly typed database code so this is more of a convenience than any real need. Compile time checking is nice but I've already had several errors that are not caught until runtime. These errors largely deal with enforcing constraints when filling a DataTable using a standard DataAdapter. Most of these errors are extremely trivial, do not interfere with my actual code and would never have been brought to my attention without strongly typed db code. So here is what I see as the major negative. I feel like I am getting much more code dependence rather than the current shift towards independence. This project largely works with data from a vendor database. If they ever update their schema (which can be as often as once a week) my app will break, even if they simply change a field from varchar(10) to varchar(12). I'm starting to lean towards either rolling my own db code or using NHibernate again. Also, LINQ seems to be a departure from this strategy as well. Does anyone else have any comments? Have any of you used strongly typed db code on a large project and found it to be indispensable? What am I missing? Thanks! Matt Penner

                    O Offline
                    O Offline
                    originSH
                    wrote on last edited by
                    #9

                    these objects can just be templated and code generated ... there are code generators out there that can use db schemas as a datasource but I've always just rolled my own code generator.

                    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