Part 05 – Code First Migrations and Azure Deployment Entity Framework and MVC Series Tom Perkins NTPCUG.

Slides:



Advertisements
Similar presentations
USING WORDPRESS. WEEK 1 1.Why WP? 2.Setting Up WP 3.Exploring the Admin screen 4.Page Organization 5.Posting 6.Polls.
Advertisements

WaveMaker Visual AJAX Studio 4.0 Training
Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
XP Information Technology Center - KFUPM1 Microsoft Office FrontPage 2003 Creating a Web Site.
Introduction to Entity Framework Part 1 Tom Perkins NTPCUG.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Using T-sql scripts. Migrating Sql Database to SQL Azure Database Create the Test Database In SQL Server Management Studio, on the File menu, point to.
Access Web Apps – OK, Now What? EXTENDING ACCESS WEB APPS George Young Dawson Butte Software ACCESS DAY – OCTOBER DENVER,
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2012 CHAPTER TWELVE (ENRICHMENT CHAPTER) Windows Store Apps.
CSCI 6962: Server-side Design and Programming
Microsoft Azure Introduction ISYS 512. Microsoft Azure Microsoft Azure is a cloud.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
Intro to Entity Framework By Shahed Chowdhuri Don’t drown in database design during WakeUpAndCode.com.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Another Method to Open WebSpace as a Web Folder Alternative Method for Creating Web Folder in WebSpace, Slide 1Copyright © 2004, Jim Schwab, University.
IT 211 Project Integration and Deployment Lab #11.
Creating a Web Site to Gather Data and Conduct Research.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Tom Castiglia Hershey Technologies
Part 04 – Preparing to Deploy to the Cloud Entity Framework and MVC Series Tom Perkins NTPCUG.
2. Introduction to the Visual Studio.NET IDE. Chapter Outline Overview of the Visual Studio.NET IDE Overview of the Visual Studio.NET IDE Menu Bar and.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
XP New Perspectives on Integrating Microsoft Office XP Tutorial 2 1 Integrating Microsoft Office XP Tutorial 2 – Integrating Word, Excel, and Access.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
CLEEN portal Setting public access to portal documents.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
An Introduction to Designing and Executing Workflows with Taverna Aleksandra Pawlik materials by: Katy Wolstencroft University of Manchester.
BIT 285: ( Web) Application Programming Lecture 15: Tuesday, February 24, 2015 Microsoft Azure Instructor: Craig Duckett.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Introduction to MVC Introduction NTPCUG Tom Perkins, Ph.D.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
January 2006Colby College ITS Setting Up Course Pages.
Database Projects in Visual Studio Improving Reliability & Productivity.
Azure databases 1. Azure storage possibilities Azure offers several storage possibilities Microsoft SQL Server database MySQL database Azure Document.
…the basics…. Wildland Fire Information and Technology Server Requirements ● Windows 7 Professional or Windows 2003/2008 Server ● Windows 8/10 (discussion)
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED CREATING A SIMPLE PROCESS.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
AZURE AD Haishi DX, Agenda Basic concepts Exercise 1: Creating a new Azure AD tenant and a new user Exercise 2: Enable web app Azure AD authentication.
Joomla Awdhesh Kumar Singsys Pte Ltd. What is Joomla? Joomla is an award-winning content management system (CMS), which enables you to build Web sites.
Unit 9 Seminar. Starting Reporting Services Reporting Service Started.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Xamarin Development with
Creating Data Base & Sql Data Source
EF Code First (Advanced)
Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek
Relational databases, and more …
Cloud Connect Seamlessly
Aqua Data Studio.
Using JDeveloper.
Creating Data Base & Sql Data Source
SOAP web services in Microsoft Azure
Presentation transcript:

Part 05 – Code First Migrations and Azure Deployment Entity Framework and MVC Series Tom Perkins NTPCUG

SOURCE See Getting Started with Entity Framework 6 Code First using MVC 5 started-with-ef-using-mvc/creating-an-entity- framework-data-model-for-an-asp-net-mvc- application started-with-ef-using-mvc/creating-an-entity- framework-data-model-for-an-asp-net-mvc- application

Part 05 Objectives You can change the data model Update the database schema without dropping and recreating the database Deploy to the “cloud” Code First Migrations Azure Deployment

Code First “Migrations” Feature In development – the data model changes frequently – Model gets out of sync with the database – When the data model changes, we have been: Dropping and recreating the database Reseeding the database with test data In production – We want to keep the data in the database – Use Code First Migrations to Update the database schema without dropping and recreating the database

Enable Migrations Follow the steps outlined in Timesaver 05 – Activity 1 (Enable Code First Migrations)

Migrations folder created by EF

Default Seed Method in Configuration Class internal sealed class Configuration : DbMigrationsConfiguration { public Configuration() { AutomaticMigrationsEnabled = false; } protected override void Seed(ContosoUniversity.DAL.SchoolContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }

Seed Method Allows you to insert or update test data after Code First creates or updates the database schema. Called after each data model change. Deployment: – After deployment, EF checks schema for change – If schema changed, Seed method is run. – Test data should be commented out.

Set up the Seed Method Follow the steps outlined in Timesaver 05 – Activity 2 (Set up the Seed method) Additional data will be added to the database when the Seed method is run

The Seed method in a nutshell … Accepts the database context as a parameter Creates new entities in the database For each entity type: – Code creates a collection of new entities – Adds each entity to its appropriate DbSet property – Saves changes to the database

AddOrUpdate Method AddOrUpdate method – “upsert” operation – Insert or update – see Students, Courses courses.ForEach(s => context.Courses.AddOrUpdate(p => p.Title, s)); First parameter passed (Title) used to check whether entity exists. May cause error if duplicates. See framework-ef-dbs.aspx framework-ef-dbs.aspx

Execute the first Migration When add-migration command was entered – EF generated code to build the database from scratch – This code is available in a.cs file in the Migrations folder. C:\ContosoUniversity\ContosoUniversity\Migrations\ _InitialCreate.cs Up() method in this file creates database tables corresponding to data model entity sets Down() method deletes them The parameter after add-migration (InitialCreate) names the migration.

First migration … In Package Manager Console – Type update-database Use the Server Explorer to verify the update

DEPLOY TO WINDOWS AZURE

Database Handling During Deployment Copying project code to server Nothing happens to DB Run deployed app; access db for first time DB match Model Create or update db schema Run Seed Method Mismatch

Get an Azure Account MSDN Subscriber – Activate MSDN benefits us/pricing/member-offers/msdn-benefits- details/?WT.mc_id=A443DD604 us/pricing/member-offers/msdn-benefits- details/?WT.mc_id=A443DD604 Windows Azure Free Trial – us/pricing/free-trial/?WT.mc_id=A443DD604 us/pricing/free-trial/?WT.mc_id=A443DD604

Create a website in Azure 1. Open the Windows Azure Management Portal – – Click Web Sites – Click New

Click Custom Create

Enter unique URL (I used ContUNTPCUGTP) Region – use default Database – Select free 20 MB SQL DB Connection String Name – use SchoolContext Click arrow at bottom for Database Settings

Database Settings Name – I used ContosoUniversityDB Server – select New SQL Server Login Name (remember these) – used for server admin Password – strong requires 3 – upper, lower,numeric, special char Region – leave default Click check to exit

Deploy App from VS to Azure

In Visual Studio Click project in Solution Explorer Click Publish

Disclaimer VS has updated the dialog boxes since the MSDN tutorial was published. I used my MSDN subscription Azure benefits to access Azure; if you use a free subscription the dialogs may be different (Important) Remember to check the “Code First Migration” check box

Connect to your Azure account If you haven’t connected to Azure through Visual Studio, you have to set up a profile to connect to your web site. Try to muddle through to get a connection set up until your Azure website appears in the dialog box below and following.

Click Validate, then Next. Do not click Publish yet!

Click the Execute Code First Migrations checkbox, then Next.

Click the Start Preview button. This will display all files being sent to Azure.

Now! Click Publish!

Upon successful deployment, your website will be displayed. Note the URL. You can access the side directly on the web here.

CONGRATULATIONS!!!