edit-article
Home
Up
Delete
Article Name:
Article Description:
[55:00]VIDEO-SUMMARY-
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">Lesson 1 - Entity Framework</h1> <h2>[WHAT]</h2> <ol> <li>] </li> </ol> <h2>[WHY]</h2> <ol> <li>] </li> </ol> <h2>[WHERE]</h2> <ol> <li>]</li> </ol> <h2>[WHEN]</h2> <ol> <li>] 2015-mm-dd</li> </ol> <h2>[EXAMPLE]</h2> <ol> <li><strong>[00:00] EF - outline course</strong></li> <ol> <li>] intro to ef</li> <li>] beginning code first</li> <li>] managing relationships -</li> <li>] managing database - migrations</li> <li>] manging transactions - dealing with the web environ ment</li> <li>] integrating extras and looking forward - stored procedures, concurrency, future in ef7</li> </ol> <li><strong>[00:00] preqequisites - course</strong></li> <ol> <li>] FOR developers -</li> <li>] c# familiarity -</li> <li>] intro to mvc - an intro level guide to the msft asp.net MVC framework, we are using MVC but its not the focus of this video, you can use EF in many different programming paradigms</li> </ol> <li><strong>[00:00] module 1 - intro</strong></li> <ol> <li>] architecture</li> <li>] intro to code first</li> <li>] generating EF classes</li> </ol> <li><strong>[00:00] architecture</strong></li> <ol> <li>] EF is an ORM, - ORM maps your database types to your code types</li> <li>] used to avoid writing repititive data access code</li> <li><span style="background-color: #c0c0c0;">] use to write code generates at all</span></li> <li><span style="background-color: #c0c0c0;">] works with all SQL</span></li> </ol> <li><strong>[00:00] EF </strong></li> <ol> <li>] EF 6.1 any project that is asp.net 4+</li> <li>] all msft SQL db's</li> <li>] programming paradigms - web forms, web api, MVC, (+web pages), wpf, wcf ,</li> <li>] newer versions to include Azure Table storage, reddis, linux, etc</li> <li>] <a href="https://msdn.microsoft.com/en-us/data/dd363565.aspx" target="_blank">supported ado.net providers</a> - most major RDBM's including mysql, oracle, IBM, sybase, postgres</li> </ol> <li><strong>[10:15] EF - features</strong></li> <ol> <li>] Full ORM to map objects to code - takes stuff in db and matches to your code and vice versa</li> <li>] Asynch queries -</li> <li>] Connection Resiliency - retry on connection failures</li> <li>] StoredProcedure mapping</li> <li>] Reverse Engineering Existing Database - create code from existing database</li> <li>] using code to create database ( code first)</li> <li>] concurrency detection -</li> <li>] enum and spatial data support -</li> <li>] many more features -</li> </ol> <li><strong>[12:00] EF - how it works ( high level overview)</strong></li> <ol> <li>] illustration - basic ] link to entities, ] convert to query, execute ] map results to entitity </li> <li>] illustration - advanced( EF system components) - ] more detailed workflow description of EF</li> <li>] this course will focus on the basic - you write some LINQ, you get results back</li> </ol> <li><strong>[13:00] EF - installation</strong></li> <ol> <li>] requires VS 2010 or ></li> <li>] use Nuget "Install-package EntityFramework"</li> <li>] comes with /MVC, /WEB FORMS, /WEB-API if Identity is used</li> <li>*] there is a gui for it, can use console ( NuGet ? EF )</li> </ol> <li><strong>[14:00] NuGet Primer</strong></li> <ol> <li>] Install-Package {PackageName} - installs latest non beta version</li> <li>] Install-Package EntityFramework - pre - installs lateste pre release version</li> <li>] Uninstall-Package {PackageName}</li> <li>] Update-Package EntityFramework - reinstall (all projects)</li> <li>] Update-Pakage EntityFramework -ProjectName MyProject</li> <li>*] 31K packages available</li> </ol> <li><strong>[15:30] DEMO - install EF into new Console application using NugetPackage manager</strong></li> <ol> <li>] new console project</li> <li>] use PM console window cmd to install EF into project</li> <li>] Install-Package EntityFramework</li> <li>] review package.config - to review packages installed, (EF 6.1.2 is the only currently installed package)</li> <li>+] REFERENCE - nuget website package name - shows addtional info details, package version history</li> </ol> <li><strong>[18:00] DEMO - install EF into new Web application </strong></li> <ol> <li>] new project - points out "Web application" template and OPTION for Identity settings - change authentication</li> <li>+] REFERENCE - MVA course on Identity by Adam and Jeremy</li> <li>] installs web application template with No authentication</li> <li>] points out EF is not installed with this template</li> <li>] then uses PM console to install EF into project as per previous DEMO</li> </ol> <li><strong>[20:15] Intro to (EF) code first </strong></li> <ol> <li>] code first - a misnomer - write code first, then the code will create the database</li> <li>] usually in enterprise development, you have an existing database and you work with that OR in some cases, design the db, but its still that's the first step</li> <li>] takes your PLAIN OLD CLR OBJECTS (POCO) and maps them to database tables</li> <li>] only requires 2 things ] a context class ] your code class</li> <li>] context class = everything you are going to do with your database, goes through your context class</li> </ol> <li><strong>[22:15] DEMO basic code first (console app)</strong></li> <ol> <li>] PROS- EF - more fluid, efficient way of developing, stay in the code,</li> <li>] example - album class, access data from database via console application</li> <li>] get count of records in db - var count = context.Albums.Count()</li> <li>] adds album to db - context.Albums.Add( new Album(){price:9.99, title="Wish"})</li> <li>] create a query against db using linq</li> <li><span style="background-color: #00ff00;">] var albums = context.Albums .Where( o=> o.Title.Contains("Wish")).ToList();</span></li> <li>] did all of this 'db work' without really doing anything db related,</li> <li>] intellitrace shows all queries you are making from your code (ultimate edition of VS )</li> </ol> <li><strong>[34:15] DEMO basic code first and scaffolding (web app )</strong></li> <ol> <li>?] ? re: data context - keep reusing the same one or create new ones - uses ADO.net behind the scenes, manages connection pooling , there wont be any performance hit by creating a new context each time, after its used it goes back into a pool, if another request comes in for same database, it uses the existing connection</li> <li>x] creates new app using template with Identity ( this includes the album framework)</li> <li>x] adds the "album" class with a Music dbContext class </li> <li>x] add controller - new scaffolded item (mvc5 controller with views using EF) - set model, set dbcontext</li> <li>*] you have the option to ADD a dbcontext if none exists, in this dialog (use the + icon beside ) -</li> <li>*] this auto generates the Controller class, contains methods for add,delete,list,edit along with view for each also</li> <li>x] access the new controllers by yourapp.com/Albums</li> <li>x] creates new album - adds and displays the album</li> </ol> <li><strong>[39:30] how does EF connect to your db</strong></li> <ol> <li>] dbs can be in many different places ( App_Data, intranet, cloud )</li> <li>] do you have an existing named connection string in your web.config?</li> <li>] if EF finds a connection string named "" in your web.config it will connect to that db (connection string named in dbContext class )</li> <li>] looks in web config for conn string named the same as you class (use ContextClass name )</li> <li>] IF <strong>no connection string</strong> found looks for ] sql express on your system, then ] local db <a href="file://\\11">\\11</a> , ] local db 12 ( mssqllocaldb) and then creates db</li> <li>] TIP you should always SPECIFY a connection string name if you know what database you are going to use</li> <li>] EXAMPLE = public MusicContext():base("MusicStoreConnection")</li> <li>] WHERE MusicStoreConnection is the name of a connection string that exists in your web.config file</li> </ol> <li><strong>[43:00] TIP checking whats installed on your system</strong></li> <ol> <li>] from command prompt or powershell</li> <li>] sqllocaldb i - mssql db installed</li> <li>] sqllocaldb v - sql server versions installed</li> <li>] be aware of what your connecting to</li> </ol> <li><strong>[44:00] Viewing - db Queries</strong></li> <ol> <li>] 3 ways to look at the queries you are generating against the db, for debugging, ...</li> <li>] vs ultimate edition has built in "intellitracer"</li> <li>] basic way - Context.database.log = s => Console.WriteLine(s)</li> <li>] free tool - glimpse -</li> <li>] Install-Package glimpse.mvc5, Install-Package glimpse.ef6</li> <li>] Intercepter - goes in .config file, outputs to a log file</li> </ol> <li><strong>[46:00] DEMO - viewing queries</strong></li> <ol> <li>] using Debug and Console.Writeline</li> <li>] using glimpse - installs the 2 aforementioned packages</li> <li>] a great development tool, like browsers f12 dev tools for your mvc app , includes realtime debugging info for sql statements as well</li> </ol> <li><strong>[51:00] Generating EF classes</strong></li> <ol> <li>] hand coding - write classes as you would normally write classes in code only</li> <li>] using a visual designer - *] the VD will be DISCONTINUED in ef7</li> <li>>] Add - ADO.net entity data model - </li> <li>] database first entity designer -</li> </ol> <li><strong>[52:00] DEMO - database first </strong></li> <ol> <li>] USE ADO.net entity data model - to point to an existing db and reverse engineer it to create the classes that you need in your project</li> <li>] ADD new item to project, new data item, ado.net entity data model, enter name of what will the dbContext class should be</li> <li>] dialog - SELECT -what should the model contain ( code first from database)</li> <li>] select or enter - connection | database</li> <li>] will visit this in more detail in another lesson</li> </ol></ol> <h2>[HOW-TO]</h2> <ol> <li>]</li> </ol> <h2>[REFERENCE]</h2> <ol> <li>]</li> </ol> <p> </p> <p> </p> <p>status - 15% completed course (+10 points) #102213 <span class="user_position_message"> in MVA ranking, </span><span class="user_position_number"># 1441 </span> <span class="user_position_message"> in your country's ranking </span></p> <p><span class="user_position_message">quiz result = 4/5 <br /></span></p> <p> </p> <p>quiz</p> <p><br />What kind of framework is the Entity Framework?<br />Which two solutions can be used to view queries when using the Entity Framework? (Choose two.)<br />x] Which three of the following statements correctly describes the benefit of using an ORM? (Choose three.</p> <p><br />Automates database queries<br />Avoids writing repetitive code<br />Creates business logic in the code<br />Handles database transactions<br />Maps multiple database tables to classes<br /> </p>