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