{"id":1581,"date":"2014-07-23T17:16:08","date_gmt":"2014-07-23T17:16:08","guid":{"rendered":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1581"},"modified":"2014-07-23T17:18:37","modified_gmt":"2014-07-23T17:18:37","slug":"should-you-use-an-object-relational-mapper-in-your-app","status":"publish","type":"post","link":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/should-you-use-an-object-relational-mapper-in-your-app\/","title":{"rendered":"Should You Use an Object Relational Mapper in your App?"},"content":{"rendered":"\n<!-- Facebook Like Button v1.9.6 BEGIN [http:\/\/blog.bottomlessinc.com] -->\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Finspiredtoeducate.net%2Finspiredtoeducate%2Fshould-you-use-an-object-relational-mapper-in-your-app%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px; height: 30px; align: left; margin: 2px 0px 2px 0px\"><\/iframe>\n<!-- Facebook Like Button END -->\n<p>&nbsp;<\/p>\n<p>When you write applications that communicate with a relational database, your design needs to solve a fundamental problem. \u00a0\u00a0In most cases, we create systems using relational databases. \u00a0(i.e. MySQL, Oracle, MSSQL, etc.) \u00a0\u00a0Similarly, we probably write our web or smart client applications using an object oriented programming language like C#, Java, Ruby, JavaScript, or Python. \u00a0\u00a0The data access layer that you write needs to connect the relational database world with the world of \u201cobjects\/methods\/properties.&#8221; \u00a0 In this post, I will review some of the benefits and challenges of using an object relational mapper, common set of tools and framework patterns to solve this mapping problem.<\/p>\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2014\/06\/openBarterModel.jpg\"><img loading=\"lazy\" class=\"alignnone  wp-image-1512\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2014\/06\/openBarterModel.jpg\" alt=\"openBarterModel\" width=\"579\" height=\"469\" srcset=\"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2014\/06\/openBarterModel.jpg 749w, https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2014\/06\/openBarterModel-300x243.jpg 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><\/p>\n<p>In my professional experience, I have found ORM\u2019s helpful. \u00a0\u00a0The problem of converting database rows into objects is not a very interesting task. \u00a0\u00a0I personally enjoy focusing my attention on the business logic, game logic, or control logic code.<\/p>\n<p><strong>Benefits of an ORM:<\/strong><\/p>\n<p>1) \u00a0\u00a0\u00a0\u00a0\u00a0Most ORM tools provide a method of mapping database table to your application objects. \u00a0\u00a0For some ORM\u2019s, the database tables are generated from application objects that you define. \u00a0You can also find ORM\u2019s that create application objects based on database tables. (Many ORM frameworks support both styles)<\/p>\n<p>2) \u00a0\u00a0\u00a0\u00a0\u00a0As mentioned before, an ORM creates a way for you to access your database tables using application classes that you didn\u2019t have to write by hand. \u00a0 Some frameworks automate the process of creating your classes from database structure. \u00a0 If you&#8217;re coding in a static language like C# and Java, your compiler can help you manage data model changes in your application over time.<\/p>\n<p>3) \u00a0\u00a0\u00a0\u00a0\u00a0Some have noted that ORM\u2019s help reduce defects in the data access layer. Why? Since the mapping process between database tables and application classes has been code generated or automated, a human being can inject fewer mistakes.<\/p>\n<p>4) \u00a0\u00a0\u00a0\u00a0\u00a0I really admire the Ruby Active Record technology. \u00a0In their ORM technology, they have created a cool system for changing the database model and the application model.The \u201cRuby on Rails\u201d migrations feature giving developers a clean system for making edits to production or test\u00a0code branches.<\/p>\n<p><strong>How do I find an ORM for my language?<\/strong><\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_object-relational_mapping_software\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/List_of_object-relational_mapping_software<\/a><\/p>\n<p><strong>What are some reasons to not use an ORM?<\/strong><\/p>\n<p>ORM&#8217;s will not work for every project.<\/p>\n<p>1) \u00a0\u00a0\u00a0\u00a0\u00a0If your current code base has complex hand coded SQL in the data access layer, it may be hard to introduce an ORM into that culture. \u00a0\u00a0It really depends on the situation. \u00a0\u00a0If you\u2019re starting a new module, you might consider testing an ORM in the bounds of that module.<\/p>\n<p>2) \u00a0\u00a0\u00a0\u00a0\u00a0ORM\u2019s have a bad reputation for configuration bloat. \u00a0An ORM has to solve the fundamental problem of mapping your database tables to your application objects. Some ORM\u2019s are very verbose. \u00a0(I tend to avoid these) \u00a0 ORM\u2019s that use conventions are often concise. \u00a0\u00a0\u00a0I encourage you to write small apps to test if an ORM is the correct choice for your team.<\/p>\n<p>3) \u00a0\u00a0\u00a0\u00a0\u00a0I\u2019m a big fan of loose coupling. \u00a0\u00a0When I design systems, I want to make sure I can test my business objects in isolation of data access.As you consider a specific ORM, \u00a0consider how much tight coupling the tool introduces between your business logic code and the data access layer.<\/p>\n<p>I hope I have given you a balanced review of the benefits and costs of using ORM\u2019s as you start your career. \u00a0\u00a0\u00a0Here are a few links that I used to research this post. \u00a0\u00a0I hope you find them helpful. \u00a0I have also included a link to OpenBarter, an open source barter system written in C# using Entity Framework. \u00a0Entity framework is one popular ORM option for the Microsoft .NET framework.<\/p>\n<p>&nbsp;<\/p>\n<p>We love to hear from our readers. \u00a0 What are your thoughts? \u00a0Are you working on any fun software development projects?<\/p>\n<ul>\n<li><a href=\"http:\/\/www.asp.net\/entity-framework\" target=\"_blank\">http:\/\/www.asp.net\/entity-framework<\/a><\/li>\n<li><a href=\"http:\/\/www.djangobook.com\/en\/2.0\/chapter05.html\">http:\/\/www.djangobook.com\/en\/2.0\/chapter05.html<\/a><\/li>\n<li><a href=\"http:\/\/guides.rubyonrails.org\/active_record_basics.html\">http:\/\/guides.rubyonrails.org\/active_record_basics.html<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/398134\/what-are-the-advantages-of-using-an-orm\/398178#398178\" target=\"_blank\">Stack Overflow &#8211; Advantages of using an ORM<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/michaelprosario\/OpenBarter\/blob\/master\/OpenBarter\/OpenBarter\/Models\/ForTradeRepo.cs\">Example add, update, delete operations in Entity Framework<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p style=\"color: #555555;\">Join the\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" href=\"https:\/\/www.facebook.com\/groups\/1529734900588516\/\" target=\"_blank\">Spark Macon Maker Space Community on Facebook<\/a><\/p>\n<p style=\"color: #555555;\">Posts From\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" href=\"http:\/\/inspiredtoeducate.net\/\" target=\"_blank\">InspiredToEducate.NET<\/a><\/p>\n<ul style=\"color: #555555;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1388\" target=\"_blank\">10+ Lessons To Help You Grow Your Skills as a Developer from Mercer GDG<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1238\" target=\"_blank\">17 Fun Tools To Teach Kids To Code by @ChrisBetcher<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" title=\"Benefits of Teaching Kids To Code That No One Is Talking About\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=623\">Benefits of Teaching Kids To Code That No One Is Talking About<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" title=\"7 Reasons Why The Makers Movement Is Revolutionary\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=942\">7 Reasons Why The Makers Movement Is Revolutionary<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" title=\"How to Build Your Mobile App using HTML\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=849\">How to Build Your Mobile App using HTML<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" title=\"Maker Camp: Free Virtual Summer Camp for Teens\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=961\">Maker Camp: Free Virtual Summer Camp For Teens<\/a><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><a style=\"font-weight: inherit; font-style: inherit; color: #0085cf;\" title=\"5 reasons to love Khan academy for computer science\" href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=202\">5 reasons to love Khan academy for computer science<\/a><\/li>\n<\/ul>\n\n<!-- Facebook Like Button v1.9.6 BEGIN [http:\/\/blog.bottomlessinc.com] -->\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Finspiredtoeducate.net%2Finspiredtoeducate%2Fshould-you-use-an-object-relational-mapper-in-your-app%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px; height: 30px; align: left; margin: 2px 0px 2px 0px\"><\/iframe>\n<!-- Facebook Like Button END -->\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; When you write applications that communicate with a relational database, your design needs to solve a fundamental problem. \u00a0\u00a0In most cases, we create systems using relational databases. \u00a0(i.e. MySQL, Oracle, MSSQL, etc.) \u00a0\u00a0Similarly, we probably write our web or smart client applications using an object oriented programming language like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,16,23,8],"tags":[],"_links":{"self":[{"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1581"}],"collection":[{"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/comments?post=1581"}],"version-history":[{"count":3,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1581\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1581\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/media?parent=1581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/categories?post=1581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/tags?post=1581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}