{"id":33429,"date":"2024-01-04T17:54:49","date_gmt":"2024-01-04T12:24:49","guid":{"rendered":"https:\/\/www.oneclickitsolution.com\/blog\/?p=33429"},"modified":"2024-01-04T17:54:50","modified_gmt":"2024-01-04T12:24:50","slug":"entity-framework-in-depth","status":"publish","type":"post","link":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth","title":{"rendered":"What is Entity Framework? Open Source Framework for ADO.NET"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-what-is-entity-framework\">What is Entity Framework?<\/h2>\n\n\n\n<p>Entity Framework is a persistence framework which helps you to access the database and load your object and save it into the database.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/Entity-Framework1.png\" alt=\"Entity Framework1\" class=\"wp-image-33439\" title=\"Entity Framework1\"\/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Types of Workflows Using Entity Framework<\/h2>\n\n\n\n<p>There are 3 workflows to build domain mode using entity framework.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/Workflow.png\" alt=\"Workflow\" class=\"wp-image-33440\" title=\"Workflow\"\/><\/figure><\/div>\n\n\n<p>Most developers use the Database First and Code First approach to developing software.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Database First Workflow<\/h3>\n\n\n\n<p>Database-first <strong><a href=\"https:\/\/www.oneclickitsolution.com\/services\/web-app-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">development<\/a><\/strong> workflow generates the context and entities for the existing database using the EDM wizard integrated into Visual Studio or executing EF commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Code-First Workflow<\/h3>\n\n\n\n<p>Use this workflow when you don\u2019t have any legacy database for your application. In the code-first approach, first, need to write entities (domain classes) and context classes and then create the database from these classes using migration commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Model First Workflow<\/h3>\n\n\n\n<p>In the model-first approach, first need to create entities, relationships, and inheritance hierarchies directly on the visual designer integrated into Visual Studio after that generate entities, context class, and the database script from your visual model.<\/p>\n\n\n\n<p>Many <strong><a href=\"https:\/\/www.oneclickitsolution.com\/hire-dedicated-developers\/\" target=\"_blank\" rel=\"noreferrer noopener\">developers <\/a><\/strong>have misconceptions about the Database First approach<\/p>\n\n\n\n<p>Database First gives you more control over the database: which is not true at all. With Code First, you have full control over the database, for example, you can create and remove stored procedures or triggers.<\/p>\n\n\n\n<p>Code First is for greenfield projects: which is also not true. You can use reverse engineering your existing database to create the code first model and then use code first migration for any subsequent changes afterward.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Few Advantages of Code First<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Full versioning of database<\/h3>\n\n\n\n<p>Using code first we can manage all versions of the database by using of single comment which is very helpful while maintaining different versions of the application. Without code first, you either need to manually take care of database versions or need to use an external tool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Productivity<\/h3>\n\n\n\n<p>Even you can use code first workflow with legacy database also, by the help of reverse engineering your legacy database to create code first model and then use code first migration for any subsequent changes afterward.<\/p>\n\n\n\n<p>For reverse engineering your legacy database Entity Framework provides Code First From Database entity data model wizard.<\/p>\n\n\n\n<p>You can also deal with multiple DBContext into a single project here are a few commands which help you to migrate the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Few Tips For Migrations<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Enable-Migrations<\/h3>\n\n\n\n<p>Enable-Migrations use only once in the entire project life.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. ContextTypeName<\/h3>\n\n\n\n<p>If you want to deal with multiple DBContext you need to specify ContextTypeName.<\/p>\n\n\n\n<p>PM&gt; Enable-Migrations -ContextTypeName Namespace.ContextName1<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. MigrationsDirectory<\/h3>\n\n\n\n<p>At the time of enabling another migration for another DBContext also need to provide MigrationsDirectory.<\/p>\n\n\n\n<p>PM&gt; Enable-Migrations -ContextTypeName Namespace.ContextName2 -MigrationsDirectory : Migrations\\DirName<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Add-Migration<\/h3>\n\n\n\n<p>Add migration command execute followed by comment and create migration script to update database changes<\/p>\n\n\n\n<p>PM&gt;Add-Migration comment<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.oneclickitsolution.com\/contact-us\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"300\" src=\"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/01\/hire-dedicated-developers-1.png\" alt=\"hire dedicated developers\" class=\"wp-image-54469\" srcset=\"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/01\/hire-dedicated-developers-1.png 1200w, https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/01\/hire-dedicated-developers-1-768x192.png 768w, https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/01\/hire-dedicated-developers-1-20x5.png 20w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">5. Configuration<\/h3>\n\n\n\n<p>The configuration is come into in picture when we enable migration it will create a configuration file.<\/p>\n\n\n\n<p>Configuration command use when we are dealing with multiple DBContext just like below<\/p>\n\n\n\n<p>PM&gt;Add-Migration comment -Configuration Namespace.configuration<\/p>\n\n\n\n<p>Namespace.configuration is a path of a respected DBContext migration configuration file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. Update-Database<\/h3>\n\n\n\n<p>Update database command executes a script created by the add-migration command and finally reflects changes into the database.<\/p>\n\n\n\n<p>Also if you are working with multiple DBContext you need to specify the configuration file path followed by -configuration command<\/p>\n\n\n\n<p>PM&gt; Update-Database -Configuration Namespace.configuration<\/p>\n\n\n\n<p>The configuration.cs file contains the seed() function where you can make the default database entry.<\/p>\n\n\n\n<p>If you having difficulty between which workflow to choose for development or having a hard time managing multiple DBContext feels free to <a href=\"https:\/\/www.oneclickitsolution.com\/contact-us\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>contact us<\/strong><\/a> for the same. With our extensive expertise as a leading <strong><a href=\"https:\/\/www.oneclickitsolution.com\/services\/dot-net\/\" target=\"_blank\" rel=\"noreferrer noopener\">ASP.Net<\/a><\/strong> web and application development company, OneClick is fully equipped to provide you with exceptional services encompassing the design and development of your applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Entity Framework? Entity Framework is a persistence framework which helps you to access the database and load your object and save it into the database. Types of Workflows Using Entity Framework There are 3 workflows to build domain mode using entity framework. Most developers use the Database First and Code First approach to &hellip;<\/p>\n","protected":false},"author":1,"featured_media":53363,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[838,784],"tags":[940,933],"class_list":["post-33429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solutions","category-web-application","tag-framework","tag-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.2.1 (Yoast SEO v24.8.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Entity Framework? Open Source Framework for ADO.NET in 2026<\/title>\n<meta name=\"description\" content=\"Entity Framework is a persistence framework that helps you to access the database and load your object and save it into the database.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Entity Framework? Open Source Framework for ADO.NET in 2026\" \/>\n<meta property=\"og:description\" content=\"Entity Framework is a persistence framework that helps you to access the database and load your object and save it into the database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth\" \/>\n<meta property=\"og:site_name\" content=\"OneClick IT Consultancy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/oneclickconsultancy\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-04T12:24:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-04T12:24:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"OneClick IT Consultancy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@OneclickIT\" \/>\n<meta name=\"twitter:site\" content=\"@OneclickIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"OneClick IT Consultancy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is Entity Framework? Open Source Framework for ADO.NET in 2026","description":"Entity Framework is a persistence framework that helps you to access the database and load your object and save it into the database.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth","og_locale":"en_US","og_type":"article","og_title":"What is Entity Framework? Open Source Framework for ADO.NET in 2026","og_description":"Entity Framework is a persistence framework that helps you to access the database and load your object and save it into the database.","og_url":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth","og_site_name":"OneClick IT Consultancy","article_publisher":"https:\/\/www.facebook.com\/oneclickconsultancy","article_published_time":"2024-01-04T12:24:49+00:00","article_modified_time":"2024-01-04T12:24:50+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png","type":"image\/png"}],"author":"OneClick IT Consultancy","twitter_card":"summary_large_image","twitter_creator":"@OneclickIT","twitter_site":"@OneclickIT","twitter_misc":{"Written by":"OneClick IT Consultancy","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#article","isPartOf":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth"},"author":{"name":"OneClick IT Consultancy","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#\/schema\/person\/c2616c0a433427a79a96fe5ca2b34ec3"},"headline":"What is Entity Framework? Open Source Framework for ADO.NET","datePublished":"2024-01-04T12:24:49+00:00","dateModified":"2024-01-04T12:24:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth"},"wordCount":636,"publisher":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#primaryimage"},"thumbnailUrl":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png","keywords":["Framework","Technology"],"articleSection":["Solutions","Web Application"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth","url":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth","name":"What is Entity Framework? Open Source Framework for ADO.NET in 2026","isPartOf":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#primaryimage"},"image":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#primaryimage"},"thumbnailUrl":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png","datePublished":"2024-01-04T12:24:49+00:00","dateModified":"2024-01-04T12:24:50+00:00","description":"Entity Framework is a persistence framework that helps you to access the database and load your object and save it into the database.","breadcrumb":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#primaryimage","url":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png","contentUrl":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2019\/04\/what-is-entity-framework.png","width":1200,"height":628,"caption":"what is entity framework"},{"@type":"BreadcrumbList","@id":"https:\/\/www.oneclickitsolution.com\/blog\/entity-framework-in-depth#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.oneclickitsolution.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is Entity Framework? Open Source Framework for ADO.NET"}]},{"@type":"WebSite","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#website","url":"https:\/\/www.oneclickitsolution.com\/blog\/","name":"OneClick IT Consultancy","description":"We Build Brands from Ideas","publisher":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/#organization"},"alternateName":"OneClick IT Solution","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oneclickitsolution.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#organization","name":"OneClick IT Consultancy","alternateName":"OneClick IT Solution","url":"https:\/\/www.oneclickitsolution.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/10\/oneclick-official-logo.png","contentUrl":"https:\/\/www.oneclickitsolution.com\/blog\/wp-content\/uploads\/2022\/10\/oneclick-official-logo.png","width":100,"height":100,"caption":"OneClick IT Consultancy"},"image":{"@id":"https:\/\/www.oneclickitsolution.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/oneclickconsultancy","https:\/\/x.com\/OneclickIT","https:\/\/www.instagram.com\/oneclick.it.consultancy\/","https:\/\/www.linkedin.com\/company\/one-click-it-consultancy\/","https:\/\/www.pinterest.com\/oneclickitconsultancy\/","https:\/\/www.youtube.com\/channel\/UCsEG6aiwOwvYrcZxMoP5xjg","https:\/\/oneclickit.tumblr.com\/","https:\/\/dribbble.com\/oneclickitconsultancy"]},{"@type":"Person","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#\/schema\/person\/c2616c0a433427a79a96fe5ca2b34ec3","name":"OneClick IT Consultancy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oneclickitsolution.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8169ffe1b63da548d77fb666e94f1aba?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8169ffe1b63da548d77fb666e94f1aba?s=96&d=mm&r=g","caption":"OneClick IT Consultancy"},"description":"OneClick IT Consultancy is the best custom software development company based in India &amp; USA with expertise in BLE, travel, mobile, and web development. With nearly a decade\u2019s experience, we use best practices and development standards to deliver high-performance applications, focused on the user experience.","sameAs":["https:\/\/www.oneclickitsolution.com\/blog\/"],"jobTitle":"Founder","url":"https:\/\/www.oneclickitsolution.com\/blog\/author\/oneclick"}]}},"_links":{"self":[{"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/posts\/33429"}],"collection":[{"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/comments?post=33429"}],"version-history":[{"count":0,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/posts\/33429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/media\/53363"}],"wp:attachment":[{"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/media?parent=33429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/categories?post=33429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oneclickitsolution.com\/blog\/wp-json\/wp\/v2\/tags?post=33429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}