{"id":197,"date":"2017-11-19T11:20:37","date_gmt":"2017-11-19T11:20:37","guid":{"rendered":"http:\/\/windows.emacslisp.com\/?p=197"},"modified":"2017-11-19T11:23:21","modified_gmt":"2017-11-19T11:23:21","slug":"code-first-entityframework-step-by-step","status":"publish","type":"post","link":"http:\/\/windows.emacslisp.com\/index.php\/2017\/11\/19\/code-first-entityframework-step-by-step\/","title":{"rendered":"Code-First EntityFramework &#8211; step by step"},"content":{"rendered":"<p>This is first post for code-first entity framework and how to use it.<\/p>\n<p>1. add entity framework, open project, in VS Package Management<br \/>\nPM>    Install-Package EntityFramework<\/p>\n<p>2. Don&#8217;t enable migrations, if you enable migrations then, add<br \/>\n   Enable migrations only after database is created.<\/p>\n<p>3. create class inherits from DbContext<\/p>\n<pre lang=\"csharp\" line=\"1\"> \r\n    public class SchoolContext : DbContext {\r\n        public DbSet<Course> Courses { get; set; }\r\n        public DbSet<Department> Departments { get; set; }\r\n        \r\n    }\r\n<\/pre>\n<p>add connection string in web.config with same name &#8216;SchoolContext&#8217;<\/p>\n<p>4. enable migrations<br \/>\ncheck screen dump, it will create &#8216;Migrations&#8217; folder and configuration.cs<br \/>\n<a href=\"http:\/\/windows.emacslisp.com\/wp-content\/uploads\/2017\/11\/enable-migration.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/windows.emacslisp.com\/wp-content\/uploads\/2017\/11\/enable-migration.png\" alt=\"enable-migration\" width=\"1500\" height=\"663\" class=\"alignnone size-full wp-image-200\" \/><\/a><\/p>\n<p>5. Add-Migration<br \/>\nPM> Add-Migration<\/p>\n<p>VS will ask you to input name and generate cs with today&#8217;s Date, check screen dump above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is first post for code-first entity framework and how to use it. 1. add entity framework, open project, in VS Package Management PM> Install-Package EntityFramework 2. Don&#8217;t enable migrations, if you enable migrations then, add Enable migrations only after &hellip; <a href=\"http:\/\/windows.emacslisp.com\/index.php\/2017\/11\/19\/code-first-entityframework-step-by-step\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/197"}],"collection":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":4,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"predecessor-version":[{"id":203,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/197\/revisions\/203"}],"wp:attachment":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}