Entity Framework Core (EF Core) 1.0
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Alternative Title |
| |
Title of Series | ||
Number of Parts | 96 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/51824 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
00:00
Software frameworkCore dumpLocal GroupPoint cloudServer (computing)Focus (optics)Run time (program lifecycle phase)Component-based software engineeringVisual systemWeightStapeldateiRelational databaseDatabaseComputing platformQuery languageEmailWeb 2.0Relational databaseVisualization (computer graphics)Cartesian coordinate systemRevision controlSoftware frameworkBitSpacetimeLink (knot theory)ImplementationLattice (order)WeightDatabaseCore dumpHuman migrationLine (geometry)Demo (music)Reverse engineeringQuery languageCodeInformation technology consultingWordSlide rulePhysical systemMereologyMultiplication signData storage deviceInjektivitätType theoryStapeldateiEndliche ModelltheorieMathematicsDampingWeb-DesignerApplication service providerOrder (biology)Open sourceService (economics)Object (grammar)2 (number)Self-organizationInsertion lossComputer fileSoftware developerContext awarenessExtension (kinesiology)Source codeAeroelasticityPoint (geometry)Well-formed formulaElectric generatorDecision theoryHypermediaBeat (acoustics)System call1 (number)Social classEvent horizonSequelInformationUsabilityArmLocal ringDigitizingAdditionConnectivity (graph theory)Hill differential equationMilitary baseComputing platformCoefficient of determinationGoodness of fitFlow separationTunisForm (programming)Computer animation
08:48
Software frameworkWeightComponent-based software engineeringCompilerLibrary (computing)Computing platformMobile WebDatabaseWeightEndliche ModelltheorieWindowVirtual machineRelational databaseRevision controlIntegrated development environmentAndroid (robot)ArmObservational studySystem callCartesian coordinate systemCore dumpSoftware frameworkServer (computing)Demo (music)outputPairwise comparisonProgram flowchart
10:01
AbstractionService (economics)Internet service providerExtension (kinesiology)Read-only memoryRelational databaseSQL ServerCompact spaceTable (information)Data storage deviceCache (computing)Context awarenessCore dumpInjektivitätLaceBefehlsprozessorComponent-based software engineeringCodeTrailGraph (mathematics)StapeldateiQuery languageAcoustic shadowKey (cryptography)Mixed realityDatabaseQuery languageMultiplication signRevision controlDatabaseGraph (mathematics)Context awarenessDifferent (Kate Ryan album)Sampling (statistics)Type theoryKey (cryptography)Software bugInternet service providerAcoustic shadowSoftware frameworkCore dumpSocial classElectronic mailing listReflection (mathematics)Arithmetic meanCuboidPairwise comparisonSemiconductor memoryStapeldateiComputer configurationInjektivitätObject (grammar)Server (computing)Service (economics)Relational databaseSinc functionDemo (music)MathematicsTrailBitConnectivity (graph theory)ImplementationMetadataQuicksortMappingException handlingCategory of beingCodeOrder (biology)Hash functionData structureEntire functionExterior algebraApplication service providerOpen sourceWindowData storage deviceStructural loadFormal grammarTable (information)Military baseStatement (computer science)PlanningElectric generatorComputing platformSequelSystem callInversion (music)Point (geometry)Forcing (mathematics)Level (video gaming)Compact spaceMechanism designProjective planeSource codeSelf-organizationStandard deviationOracleArm40 (number)Dressing (medical)Directed graphLocal ringComputer fontComputer animation
18:07
Execution unitDemo (music)Computer fontVideoconferencingSoftware frameworkEndliche ModelltheorieSocial classHand fanForm (programming)SequelCausalityNumberSource codeComputer animation
19:01
Session Initiation ProtocolExecution unitSoftware bugContext awarenessConnected spaceOrder (biology)DatabaseCodeInternet service providerSpacetimeGame controllerMathematicsRevision controlBitSet (mathematics)Point (geometry)WeightComputer configurationUsabilityLatent heatType theoryConstructor (object-oriented programming)Demo (music)System callObject (grammar)ImplementationNamespaceEndliche ModelltheorieAdditionLocal ringNumberSocial classWorkstation <Musikinstrument>InformationExecution unitForm (programming)Configuration spaceServer (computing)Data storage deviceHuman migrationWaveOcean currentService (economics)SequelString (computer science)Software frameworkDifferent (Kate Ryan album)Application service providerQuery languageMobile appWeb 2.0Link (knot theory)ExpressionEntire functionCore dumpQuicksortRelational databaseSource codeComputer animation
24:38
Demo (music)Execution unitSoftware frameworkQuery languageCodeDatabaseBitLink (knot theory)Type theorySocial classMultiplication signEndliche ModelltheorieObject (grammar)Core dumpConnected spaceString (computer science)Computer configurationContext awarenessAdditionSource codeComputer animationJSONXML
25:59
Hill differential equationExecution unitFingerprintVideo gameVacuumComputing platformAzimuthDifferent (Kate Ryan album)CodeDatabaseBitQuery languageTable (information)InformationMechatronicsDemo (music)Software bugFunction (mathematics)Mobile appInternetworkingSelectivity (electronic)Connected spaceWindowFocus (optics)AdditionMultiplication signStatement (computer science)Physical lawBand matrix2 (number)Form (programming)Compilation albumRight angleCausalitySystem callObject (grammar)SequelStudent's t-testDampingHuman migrationHeat transferElectronic mailing listSampling (statistics)Roundness (object)TwitterStructural loadCore dumpServer (computing)Software frameworkResultantRow (database)MultiplicationProfil (magazine)Insertion lossSoftwareSource codeComputer animation
32:46
Execution unitMessage passingCellular automatonCASE <Informatik>Drum memoryInternet forumSimulated annealingPoint cloudLattice (order)Statement (computer science)Selectivity (electronic)Interior (topology)DatabaseQuery languageResultantRow (database)Cartesian coordinate systemNumberSet (mathematics)Electronic mailing listObject (grammar)CodeSingle-precision floating-point formatStructural loadMilitary baseComputer animation
35:12
Execution unitChi-squared distributionMenu (computing)Selectivity (electronic)Category of being1 (number)Table (information)Beat (acoustics)MetrePoint (geometry)MappingSequelClient (computing)Stability theoryCodeForm (programming)Cartesian coordinate systemObject (grammar)Computer configurationStatement (computer science)QuicksortResultantVisualization (computer graphics)Compilation albumElectronic mailing listSource code
37:19
VacuumQuantumTrailFluidCellular automatonPairwise comparisonOrder (biology)Translation (relic)Regulärer Ausdruck <Textverarbeitung>View (database)MetadataSemiconductor memoryQuery languageString (computer science)DatabaseDemo (music)Software frameworkBitType theoryCore dumpStatement (computer science)Link (knot theory)System callWorkstation <Musikinstrument>DataflowMessage passingUsabilityForm (programming)Electronic mailing listCompass (drafting)CodeRun time (program lifecycle phase)Computer animation
39:50
Execution unitReflection (mathematics)Cartesian coordinate systemOperator (mathematics)Software frameworkSelectivity (electronic)Operating systemObject (grammar)Line (geometry)Order (biology)Endliche Modelltheorie2 (number)LogicCAN busMappingDatabaseType theoryCodeTable (information)MetadataInformationServer (computing)Different (Kate Ryan album)Revision controlBitEntire functionMultiplication signContext awarenessCategory of beingVideoconferencingSampling (statistics)Right angleExtension (kinesiology)Core dumpMathematicsCASE <Informatik>Amenable groupSubject indexingPolarization (waves)SpacetimeLink (knot theory)WebsiteGroup actionPolarization (waves)System callDemo (music)Execution unitKey (cryptography)DemosceneJSONXMLComputer animation
45:35
MIDIExecution unitDivision (mathematics)Convex hullType theoryInjektivitätService (economics)Interface (computing)MultiplicationServer (computing)DatabaseStapeldateiSoftware frameworkFactory (trading post)File formatFunction (mathematics)Internet service providerVideo game consoleQuicksortContext awarenessComputer configurationCore dumpDefault (computer science)Multiplication signEvent horizonLoop (music)MathematicsLoginEntire functionElectronic mailing listFunctional (mathematics)Object (grammar)Maxima and minimaGraph coloringConnectivity (graph theory)String (computer science)InformationHooking2 (number)Different (Kate Ryan album)Level (video gaming)CodeSocial classInsertion lossLatent heatTable (information)State of matterSQL ServerApplication service providerMessage passingOrder (biology)Tracing (software)Letterpress printingImplementationStatement (computer science)Front and back endsLocal ringSource codeSoftware bugVideo gameEndliche ModelltheorieCategory of beingForm (programming)Goodness of fitWindowDisk read-and-write headMechanism designExtension (kinesiology)System callMultiplication tableSound effectSource codeComputer animation
52:50
Execution unitFingerprintRootInformationCore dumpSoftware bugObject (grammar)Internet service providerContext awarenessGame controllerDatabaseExecution unitStatement (computer science)Service (economics)NumberSampling (statistics)MathematicsElectronic mailing listServer (computing)DemosceneMessage passingBitStapeldateiTable (information)SequelConnected spaceComputer configurationDifferent (Kate Ryan album)Projective plane1 (number)Computing platformMultiplication signSystem callFunction (mathematics)Type theoryMusical ensembleVideo game consoleEscape characterWordCodeData storage deviceSession Initiation ProtocolInsertion lossTrailContent (media)Single-precision floating-point formatDemo (music)Software frameworkApplication service providerDynamical systemEqualiser (mathematics)Set (mathematics)CircleSQL ServerCartesian coordinate systemWeightControl flowWater vaporSource code
58:29
Social classError messageSQL Server 7.0Internet service providerVenn diagramExecution unitGamma functionJukeboxHand fanChemical equationThomas KuhnPlanar graphMiniDiscRule of inferenceGraph (mathematics)State of matterInsertion lossSystem administratorWeightObject (grammar)LogicDatabaseCodeIdentity managementMathematicsServer (computing)BitInternet service providerOrder (biology)Type theoryLevel (video gaming)Virtual machineError messageComputer configurationDifferent (Kate Ryan album)WindowMultiplication signSingle-precision floating-point formatSystem callData storage deviceService (economics)Physical systemRelational databaseLatent heatContent (media)Source codeComputer animation
01:04:09
Type theoryComplex (psychology)Texture mappingInheritance (object-oriented programming)Twin primeData storage deviceData modelDatabaseMaxima and minimaAxiom of choiceCore dumpCodeCompilerWeightComputing platformRepository (publishing)BlogDemo (music)WikiSoftware frameworkLink (knot theory)Table (information)Core dumpWindowSubject indexingSheaf (mathematics)Type theoryChainObject (grammar)Relational databaseGroup actionContext awarenessMappingArithmetic progressionCASE <Informatik>System callQuicksortMathematicsSequelDiffuser (automotive)Mixed realityRevision controlStatement (computer science)Computing platformMilitary baseGodDifferent (Kate Ryan album)Forcing (mathematics)Arithmetic meanDatabaseStudent's t-testCategory of beingForm (programming)PlotterStructural loadDemo (music)ArmGreatest elementProjective planeApplication service providerExterior algebraSoftware testingWeb 2.0Software bugClient (computing)Key (cryptography)Procedural programmingUniverse (mathematics)Software frameworkCodeInheritance (object-oriented programming)Acoustic shadowLatent heatMultiplicationWeightTrailInternet service providerComputer animationXML
Transcript: English(auto-generated)
00:05
Oh, my microphone is on. So this is probably a good time to start. Good morning, everyone. Welcome to the second day of NDC, unless you've been here since Tuesday. My name is Ido Flatow. It's a strange name. I know that's because I'm from Israel.
00:22
And this session is about Entity Framework Core. I'm guessing some of you are still familiar with the old name, Entity Framework 7. Same thing, new stuff. They changed a bit the things, as they always do in beta versions. So just a couple of words about myself before we begin.
00:41
As I said, my name is Ido. I am a consultant and an architect in a company called Selagu, based in Israel. Among my other titles, I'm a Microsoft MVP and the regional director, which basically means that I go to a lot of conferences to talk about Microsoft technologies that I like, mostly.
01:01
And in addition, I wrote a couple of books on .NET and about web development, created a couple of courses for Microsoft. Anyone doing official Microsoft courses? No? That's the reason I don't get any money from it. And among other things, I manage a couple of communities in Israel, the Azure community,
01:23
web development community. So next time you're in Israel, just send me an email. I'll tell you when our next meeting is, unless you prefer to travel. And first of all, let's talk a bit about Entity Framework. But first, how many people are currently using Entity Framework? In hibernate, anyone?
01:42
Go outside, please. Nothing for you to do here. So Entity Framework 7, has someone already tried that out? 7 or core? The LC1 version, the LC2 version, LC2? Yeah? OK. If you want, I can talk a bit about migrating
02:00
from earlier versions to the new version, because I had to migrate all my demos a couple of weeks ago. And that was kind of painful. So I might talk about that a bit. So let's talk a bit about history, mostly because I do development for 20 years. So history is practically the things
02:20
that I talk about most of the day. So at the beginning, we had Entity Framework 0.1, if someone remembers that version. I remember that version back in, I think, it was 2008 or 2009. But the first actual version of Entity Framework that was usable was Entity Framework 4, which came out in .NET
02:41
4, was a part of the .NET Framework, as you remember, came with Visual Studio with all the EDMX designer and such. Then we had the different versions of 4.x, 4.1, 4.2, EF5. Then we had EF6, which had a lot of new stuff that
03:01
improved Entity Framework. At this point, Entity Framework was already a NuGet package, an open source code. The design was open to the community to comment on. And the reason there is a blank space here is because the next version of Entity Framework is going to be Entity Framework 6.2,
03:21
not currently available. They will work on it after EF Core is released, when they have the manpower to work on that stuff. But currently, if we look at Entity Framework Core, Entity Framework Core 1.0, to be more exact, Entity Framework Core is going to be the same as Entity Framework 6, where it comes to how you obtain it
03:40
and how you use it in your application. So it's going to be a NuGet package. It's already a NuGet package. For the tooling, there are currently not much tools for Visual Studio itself, more for command line tools for migrations. But still, stuff will be shipped after the V1 release. So if you look at today at Entity Framework,
04:02
Entity Framework 6, as you raise your hands, most of you are using Entity Framework 6 or some other version of it. It's mostly for relational databases, right? SQL Server, sometimes we use it for Oracle, DB2 maybe. But Entity Framework 6 is mostly for relational.
04:22
I'm saying that especially because Entity Framework Core brings a couple of new features, including non-relational database support, OK? Second, Entity Framework is quite large. If you look at the DLL files of Entity Framework 6, it's about five, six megabytes in size. If you include the documentation for IntelliSense,
04:42
it's another three megabytes. Entity Framework Core will also change that. It runs only on the full DLL framework, currently 4.5, 4.6, depends on what you're using. And of course, there are stuff that are currently missing from Entity Framework stuff that we all want, such as that wonderful batch update
05:03
where we can just say, save my changes, and it will not generate 10,000 SQL inserts into the database and run them one after another, OK? Yeah, I see some smiles, so that means you encountered that issue. I'm not saying there is no support for that at all because there are open sources you can download from GitHub,
05:21
some extensions to Entity Framework that implement that. But you know, it's not a documented feature, it's not a supported feature. Like many open sources, you might find it useful, you might find it unusable, or you can't implement it in your organization because it's a source that was written back in 2014 and no one is maintaining that, OK?
05:42
So it depends on you if you want to use that or not. A bit about the core features of Entity Framework Core. And by the way, most of the session today will be demos, OK? I have a couple of slides, but we'll go straight to demos and we'll just show all of these new features. I don't have any slide that actually explains
06:01
each of the features, so you have to stick around in order to understand what Entity Framework Core is. You just can't go outside and then download the slides. So first of all, Entity Framework Core is not an update to Entity Framework 6. It's an entirely new framework. It's written from scratch. Of course, they still try to maintain the same things.
06:21
I mean, they won't ask you to change DB context into something else. It's still called DB context, it's still called DB set, but it's written from scratch. I'm not saying that they didn't copy paste some code from before, but it's written from scratch. For example, there is no object context in EF Core, OK? So if any of your code was built on that,
06:41
you'll need to change it a bit. It supports new platforms, platforms, I mean operating systems. We'll see a slide about that shortly. And new data stores, as I mentioned, not necessarily relation database, but other types of stores. It's very friendly to IOC, to dependency injection.
07:03
That's because in Microsoft in the past couple of years, they embraced IOC and embedded it into a lot of frameworks. If you remember, is anyone using Web API today? So Web API, from the first version, it used a lot of IOC. ASP.NET Core, what was once known as ASP.NET 5,
07:22
uses a lot of IOC, and so does Entity Framework Core. And because it's using IOC, it's a lot easier today to implement stuff for Entity Framework, to customize the services that are embedded into Entity Framework. Okay, so we can just replace them in a second, plus the 10 hours it takes you to write the code
07:41
that actually extends that component. In addition, they invested a lot in optimizing the query that are generated by Entity Framework, the link queries and the SQL queries. We'll talk about that later on and see a demo for that. They removed something that was called model first.
08:00
Anyone still using EDMX files? EDMX files, anyone? Okay, so you'll need to change your code a bit. No more model first, only code first. You can still do reverse engineering of the database into classes, there are tools for that. But if you were planning on using a designer to design the entities and map them
08:21
to the data store, that's gone. Maybe it will be added by third parties, but not for Microsoft. And of course, one thing that we got in Entity Framework, I'm still saying Entity Framework 7, because core is still quite fresh in my mind. So another thing that we got in Entity Framework Core is the support, the actual support
08:42
for batch updates, batch inserts, and we'll see that also in a demo. In regards to new platforms, as I said before, Entity Framework 6, only the .NET framework, but today we have a couple more frameworks in the .NET environment, the .NET Foundation.
09:04
We also have .NET Core, and we have the Xamarin framework, which runs on Mono. If you're familiar with that, if not, there were a couple of Xamarin sessions, I think, yesterday, you can check them out. So .NET Core can run on any platform, Windows, Linux, Mac.
09:20
Xamarin is mostly intended for cross-platform mobile devices. Entity Framework Core, in comparison to Entity Framework 6, can actually run on all of those target frameworks. So whether you're targeting Windows, whether you're targeting an application for iOS or for Linux or Mac OS or Android,
09:42
you can use Entity Framework Core. It will actually depends on which database you're going to connect to, because I haven't seen anyone installing SQL Server on the Linux machine yet. They say that the next version will support that. But if you're trying to connect to a remote server, you will be able to do that. And we'll see a demo for that.
10:02
Okay, so regarding the new data stores, as I mentioned before, not only relational data stores. So of course, Entity Framework will support SQL Server, Oracle, all the other relational databases. Of course, depending on the companies that will create providers for them. The initial version of Entity Framework Core
10:23
supports SQL Server, of course, SQLite, SQL Compact, and Postgres. That's an open source provider that you can add on top of Entity Framework Core. As for other databases, Oracle DB2,
10:41
what's the name? What's it called? Forgot the name of the third database. I wanted to say. Basically, you need a provider for that. But once EF Core is released, it's version one, probably companies will go ahead and write their providers for that. As for other data stores, if you look back at the history of Entity Framework Core when it was known as Entity Framework 7,
11:03
in the earlier versions, the beta versions, you could have seen samples for non-relational databases, such as Azure Tables, which is a key value storage, and Redis, which is not only a key value cache, but it also supports lists and hashes and that sort of stuff. There were samples on how to use EF Core for that.
11:24
In version one, they just removed all of those samples because, well, basically they didn't work. But once version one is released, which will be in a couple of weeks, alongside with ASP.NET Core 1.0, they are going to go back to that and work on those samples.
11:42
Okay, it's in the backlog. It's tough to do after version one is released. So I'm guessing that by the end of the year, you will see providers for Redis cache, table, storage, of course, probably for other stuff too, such as, I don't know, maybe S3, or maybe DynamoDB, Amazon DynamoDB.
12:04
You probably see more and more providers since it's becoming very easy to implement those providers. Okay, so version 1.0, only relational databases. We'll see some of those in the demos. As I mentioned before, Entity FermiCore is very lightweight.
12:22
So first of all, it's about one megabyte in size, okay? And it's rewritten. So no more the large object context under the hood in your DB context. You get the simple DB context, you get the simple DB set, but it's a lot more lightweight. But that lightweight comes with new implementations
12:43
of known concepts in Entity Framework, such as the metadata structure that maps your object store to the data store. That has improved. We'll see a demo for that. The entire change tracking in Entity FermiCore
13:01
has changed a bit, a bit meaning it doesn't work like the old one. So if you're using change tracking to say attach objects that you get in a service to an object context or DB context, and then save them to a database, assuming that they will automatically, automatically be marked as added or updated,
13:21
modified, deleted, that sort of stuff, that will probably won't work out of the box as you expect, okay, in comparison to EF6. But we'll see demo on how to tackle that and handle that. As I said before, almost all of the components in Entity FermiCore are injected into Entity Framework.
13:41
Does it mean it's slower? It's actually faster in some aspects, but what you do get is the option to override some of those injections or all of those injections and bring your own code. If you want a different type mapper for your database, you can do that. If you want to add your own logging mechanism, you can do that, okay?
14:01
A lot of the concepts or the services in Entity Framework, you can just go ahead and replace them. It's not anymore internal classes as we had in Entity Framework 6 and earlier versions, okay? So for me, for example, as someone who used reflection in order to get those internal types and then change the values, such as changing schemas on the fly,
14:22
that is a lot easier now with Entity Framework 7. And of course, some of the API has changed. For example, the change tracking API has changed, but we'll go over the demos and you'll get the grasp of what actually changed underneath the hood. And of course, EF Core has been optimized.
14:42
They improved the queries, the SQL queries that are executing in the database. We'll see some of those. And the concept of Entity Framework now is what is called pay-per-play, meaning that when I start a project, I don't need to bring the entire NuGet package
15:00
of all the Entity Framework support for SQL Server and Oracle and other stuff. I'm just getting the core itself, which is under a megabyte, and then I add the stuff I want to it. I want to support Postgres. I only add the Postgres NuGet package. I don't need the SQL Server NuGet package as it is now separated, unlike, for example, Entity Framework 6,
15:20
where I added Entity Framework and added the SQL Server support, even if I haven't used it, okay? So the question I'm guessing that some of you are asking, if not all of you, is what will happen to Entity Framework 6? Is this the end for Entity Framework 6 as we might have heard?
15:40
So the answer is it's not the end for Entity Framework 6. Since a lot of people are still using Entity Framework 6, Entity Framework 6 is different than Entity Framework 7 in several aspects. It will continue to evolve. It won't evolve in the same speed as Entity Framework 7, of course, Entity Framework Core, sorry, but you'll actually see new stuff coming out,
16:02
improvements, of course, bug fixes, okay? It just might take more time to release new versions, okay? So don't expect Entity Framework 6.2, 6.3, 6.4, 6.5 by the end of the year. Probably 6.2 will be the next major version
16:20
of Entity Framework. So some of the new features that I'm going to show very soon in demos, are the new actual features of Entity Framework Core aside from new platforms, new providers. First of all, we have new options of mixing queries
16:41
that will run in the database and in memory. Entity Framework Core now supports a better understanding of what goes in memory and what goes in a database, and not throwing you exceptions that you cannot do this in a database. We have the support for batch save. So when you call save Async, save changes Async,
17:01
it will actually do batch inserts, batch updates. We see that. SQL query improvements, some things have changed. For example, when you do an eager load using an include statement, the SQL query that runs in the database is actually improved and it works faster.
17:21
Some new features such as shadow properties and alternative keys. We'll talk about that using a demo. And there is a new API for change tracking called the track graph API, which basically lets you control how the entities will be attached to the DB context.
17:43
Again, we see that in a demo. So let's go ahead and start with the first demo showing some of the basics of Entity Framework. Now I'm using a Mac, but let me just switch to my Windows machine. We'll see Entity Framework running on a Mac by the end of the session. Don't worry, okay?
18:03
So let's start with Entity Framework, the basics. Okay, so first of all, can you see the fonts all right, or do I need to increase? Yeah, it's okay? Okay, so first of all, if you look at my standard objects, the DB context, the DB set,
18:21
this is the same as Entity Framework 6. Okay, nothing has changed in these classes. By the way, for my demos, I will use Star Wars. I saw one speaker talking about Entity Framework using demos from the model of the Seven Summaries video. And because this is Entity Framework 7,
18:42
so I need to use the number seven. So I thought, what movie has seven prequels and sequels? And the answer is Star Wars. So to do this demo, by the way, I used an API because I don't know all the things there is to know about Star Wars. I'm not that of a fan. There is an API called SWAPI, which is Star Wars API.
19:05
Okay, so if you want to learn more about what is the height of Luke Skywalker or how much does he weight, you can do that. Okay, there's a cool API for that. So I use some of these in my demos. So I didn't invent anything.
19:22
So let's take a look at the basic DB context. As you are familiar with DB context, you can get the connection string in a constructor in Entity Framework 6, Entity Framework 4, it's a bit different. We now use a DB context options. DB context options is basically an options object,
19:42
which allows you to specify which database provider I'm using. So I don't need to specify that in the connection string, in my app settings or web config or whatever it is. I can just specify the type of the provider I'm using in code and inject that into my context. Okay, so for example, in this demo,
20:02
I'm using my local SQL express. So I'm creating a new DB context options builder, which will create my options object. I'm telling it I'm using SQL server, providing the connection string. Of course, you can provide the connection string from a configuration file, from, I don't know,
20:20
some kind of a secured storage or some sort. And then I'm creating the context using those options. Okay, I can of course control other stuff here, like the change tracking, the database settings, all the other stuff that we're used to doing in Entity Framework 6. I'm just doing that for an options object.
20:41
And that aligns quite well with Entity Framework Core when you're using it in ASP.NET, because that way ASP.NET knows automatically how to inject that options object into your context. Okay, now, as you can see, there is a new command here called ensure created. If you're looking for those whole
21:00
database initialization classes of Entity Framework 6, they drop creative database if a model changes and that sort of stuff, all the seed methods, that's currently not available in EF Core. It will be available, some of it will be available after version 1.0. So the current way of verifying your database exists
21:23
is either calling ensure created or using the migrations command from command line. But as you can see, there is no way of doing a seed method here to insert the basic entities you need in the database. That will be added after version 1.
21:42
Other than that, it's mostly the common stuff of Entity Framework that we're usually doing. We're creating a new object, we're adding that into a certain DB set, and then we call save changes. Save changes, of course, the implementation is a bit different, but when we get to the point where we talk about performance, I'll show exactly what's going on
22:02
underneath the hood in the database. After that, simple link queries work just the same. Even advanced link queries work just the same. Okay, just create your link query, do a to list, to array, whatever you like, iterated normally just works the same.
22:21
The same concepts apply in Entity Framework 6. So if your entire code of Entity Framework 6 is simple as that, which is never simple as that, but let's say it's simple as that, migrating from Entity Framework 6 to Entity Framework Core just means change the constructor of your DB context, and of course, replace the NuGet packages.
22:40
So let me just point to which NuGet packages we're using. I'm using currently two specific NuGet packages from Entity Framework. Okay, so the first package I'm using is Entity Framework Core. This is the base package that you need
23:01
to get all the Entity Framework Core features. And since I'm using SQL Server as the provider, I installed another NuGet package, which brings the relational NuGet package in addition. And that is the Microsoft Entity Framework SQL Server NuGet package. If I didn't want SQL Server, if I wanted to say Postgres or SQLite,
23:22
I will just remove this NuGet package and add a different NuGet package instead, okay? By the way, since the SQL Server NuGet package depends on the Entity Framework Core, it's simple enough to add the Entity Framework SQL Server NuGet package, and that will add all the other packages that are required. Okay, so don't have to do too many stuff though.
23:43
So as I said, I'm using version RC2, which is the latest version we have now. If you have code that was written in RC1, basically it means upgrade the version of the NuGet package and change the namespace, okay? The namespace before was,
24:02
if today it's Microsoft Entity Framework Core, before it was microsoft.data.entity, okay? So we just need to remove the data, add Framework Core, and that's it. You can still use the old types of constructors where you get a connection string instead of an options object in Entity Framework RC2,
24:22
that will also work. But basically, as you can see, this is quite straightforward, just as using Entity Framework 6, okay? Looks simple enough, right? Well, wait and see. Okay, let's go to something a bit more advanced.
24:42
Let's talk about link queries, SQL queries, how they're underneath the hood in the database. Okay, so what I have here, I have code that uses both Entity Framework 6
25:00
and Entity Framework Core, just so we can compare some of the stuff. For example, how include eager loading works in Entity Framework 6 and Entity Framework 7 to compare the SQL queries. Has anyone ever tried to check what type of SQL queries are generated by Entity Framework? Anyone ever tried that? Yeah, to check when stuff works slowly, why?
25:22
Okay, this is something we usually need to do. So let's see what's happening here. So first of all, the entity model that I'm using is the same in both of the classes. Okay, it's that same person, and this time I also have a starship, okay?
25:42
And I have a DB context that currently has only the people list, and here as well, okay? And this is Entity Framework 6, so I'm just adding the connection string in the constructor, not using the options object of EF Core. In addition, I have a data initializer
26:02
for both databases. I didn't use the EF6 data initializer with the seed, just the same method, so it will be easier to compare. Okay, so clearing out the databases and seeding the data. Same Entity Framework 6 and EF Core, okay?
26:20
Same code, you can compare it afterwards. The only difference is, here I'm using ensure created in EF Core, okay? So let's compare the code itself. Okay, so what I'm doing here, first start with the eager load. I'm warming up the databases,
26:40
both the EF Core and the EF6, and then I'm doing a simple eager load. Okay, as you can see, this one uses EF Core, second one uses EF6. Well, I run the same SQL query, selecting a specific person from the people table, and I'm using eager load to also load the starships.
27:04
Okay? And of course, I run it for each query to print both the person and the starship. So first of all, let's just run this as it is and verify the results are the same. Oop, that's wrong.
27:22
No errors, let me check this for a second. I think this is causing a few bugs right now, come on.
27:42
If nothing works, we'll just run the executable. It compiled last night, so there is no reason why it doesn't work. Now, the demos will work a bit slowly at first because I've actually deleted all the databases
28:02
that I had in my server. So it's spending a couple of seconds in addition for the EF6 and the EF Core to create the database. Okay, so it takes a couple of seconds more, but this is not the final performance that you see in Entity Framework Core. Let me run that again.
28:24
Okay, so as you can see, it runs faster and it's the same output. I will fix this, it doesn't run in a second. But let me try to show you what goes on in the database and let me use an SQL profiler to record everything.
28:41
Just run the executable here again. Okay, so what I'm mostly interested is in the SELECT statements. There is a couple of SELECT statements that run during that ensured database created at the beginning, so that's less interesting for me. In addition, after I delete the list of people,
29:03
I'm inserting new stuff, so there are a couple of inserts here that I'm not interested in. I just want to show you, for example, first of all, the SQL queries for the eager load. Okay, so let me just do this first.
29:24
No, this is the migrations. Okay, so something is missing here. Just run this again.
29:52
For some reason, I'm not seeing the SQL query for EF6, but let me just talk a bit about the SELECT query for EF4.
30:01
This is how it goes in conferences. Sometimes demos mess up, but we'll get to that and fix everything. Okay, so let's talk a bit about eager loading. Has anyone seen eager loading SELECT queries in EF6? Has anyone ever noticed how that works? Basically what it does, if you SELECT from person, from people,
30:21
and include something from the Starship, it will create an SQL query with a join between the two tables, and it will actually select all the data from the people list for each of the rows in the Starship. Okay, it will do a Cartesian multiplication for the join query, because it actually outputs one table
30:41
that includes information from both tables. Okay, so if I have one person and six Starships, I will get the information for that person six times, the same information. And that, of course, affects network bandwidth, it affects the amount of time it takes to deserialize those objects. Okay, it takes more time to create the objects.
31:01
But if I look now at EF Core, so first of all, as you can see, so which thing am I running here? Oh yeah, okay. Now understand, it is running the different kind of code. Let's build this again. It ran the other sample.
31:21
Okay, let me see if this is updated. It's 1130. Just check something. Something is not working properly. Let me just try and run this again. It's using the, come on. Okay, we'll do what is known as close all the windows,
31:43
start over again. Don't worry, we have enough time. If nothing works, I'll just move it to the Mac. If nothing works, we'll just create it from scratch.
32:02
I mean, it's not that a lot of code. Okay. I have internet connections, everything should be okay. Okay, will it compile? Come on, bets, people, bets. Will it compile? Well, it will compile, will it run? Okay, that's another thing.
32:21
Okay, run, please. Yeah. Applause, anyone, for my PC? No, that's okay. Okay, so now let's look at the queries. Oh, now it's working. Okay, so first of all, my first one was, let's see, the first one is EF Core, right?
32:43
So first one is EF Core, second one is EF6. So let's look at the queries for EF6 first. As you can see, there is a very large select statement here, okay? From people, left outer join Starship, which basically, if I copy paste this into the database,
33:05
just refresh the databases here. If you look at what is selected here, well, we have one Starship, but say added another one,
33:31
and then run this again. As you can see, the same text appear for the second row, even though I'm basically doing a join,
33:40
I want one row of the person and two rows of the Starships. Now, if I go back to this code and look at what happened in EF Core, so what we see here is that this query was actually split to two different queries.
34:01
Okay, now I know you think two queries is more than one query, so it will work slower. Well, that's not actually true. It mostly depends on the number of joins that you have in your single large query. If there are multiple includes and you generate a lot of left outer joins, it will actually work slower
34:21
than just sending two or three queries to the database. Okay, so what we actually get here is one query that selects the person, okay? And a second query, as you can see, that selects the Starship where the Starship matches that single person.
34:41
Okay, so I'm running two queries, one to select the person objects that match the query, and the second query to select the Starships that match the list of people that I got before. So the result set will be smaller. I'll get a single result set for the people and the single result set for the Starship, and then of course the matching between them, the join, will be done in memory, okay?
35:01
But that will actually perform a lot better in the database than using a left outer join that brings a whole lot of data into the application. Okay, so that's for eager loading, and that's how you make Visual Studio work. Just close everything, open it up again.
35:20
And another thing I want to show is how we mix client and SQL statements today in EFQL. So let's say that you want to select from, not from a table, but from a view. Maybe you're creating some sort of a multi-tenant application, and you want to inject into the SQL statement
35:41
the tenant ID that you're currently using, and you can't use the built-in code-first mapping between an entity and its table. Okay, you want to select entities from a given table using SQL queries, and you want, of course, to translate those results into objects. Now we had that option, of course, in Entity from Work 6.
36:03
In Entity from Work 7, it has changed a bit, and it's actually been improved. So let's see what we have here. First of all, I'm using the same select statements, select from people where height is more than 1.5 meters.
36:20
If you're unfamiliar with this syntax, this syntax is C sharp six, which allows me to plant, for example, here I'm planting the name of the height property, which basically I could have just written that as height. Okay, but that wouldn't survive,
36:41
for example, a situation where I change the property name, and this way, this will actually cause my code to not compile anymore, so it's actually safer. And I'm ordering by descending height, okay? So for example, let me just run this with EF6 first.
37:05
Okay, let me clear this list here. And let's see what gets generated with EF6, okay? Let's take a look at the select statements.
37:23
Now, as you can see, for example, the order by isn't here. Why is that? Because it couldn't understand how I wanted to do an order by on top of a string SQL statement, so we just ran the SQL statement, pulled the information, and ran the order by in memory.
37:42
If I use EF7, EF core, again, my apologies, I'm still not accustomed to saying EF core. Running the same query, but now let's look at the database.
38:03
Okay, all these stuff at the beginning is the whole initialization. I'm deleting all the people, inserting them again, so it has a bit of SQL that it needs to generate. So now if you look at the generated SQL statement, you see that that order by is added
38:20
to the SQL statement. So in RTT framework's core, sorry, the translation from link queries into SQL queries is a lot better. It knows how to figure out order by, where statements, select statements, and push them into your select query so you can select from views
38:41
and still gain the same performance in the database. Now, since we are, sorry, since we are using EF core, we have a couple more stuff that we need to look at, so let's move on. But as you can see, there are a lot of improvements that can be done here, and of course, EF core is still able
39:01
to run stuff in memory. So if you write, for example, an order by where you call into a method that does the order by encode, okay, for example, I know, compares it with some string comparison or regular expression comparison that you're using, it will know how to run stuff in the database, put it in memory,
39:20
and then run it in memory for the rest of the query that you need to create, okay? So let's go on and talk about another demo for metadata API. Okay, so how many people ever needed to fetch metadata from EF6?
39:44
Just me and you? Okay, tell me your story afterwards. Because usually when people need to get metadata from the entity framework while in runtime, I'm guessing, the question is, why or why are trying to do that?
40:01
And the reason why we say why or why is because some of it is so internal that we need to use reflection to do that. And reflection sometimes works, sometimes doesn't, depends on the permissions the application has in the operating system, which basically is just depressing. Okay, so let's take a look at EF6 mapping.
40:24
Okay, so I won't bother you with the code because it's ugly code. You need to take your DB context, you need to convert it into an I object context in order to fetch the object context from it because the entire metadata workspace
40:42
is in the object context, the old object context of EF4. And then you need to do some ugly stuff, convert into another ugly stuff, try to get items, iterate them. Basically, how many lines do we have here?
41:01
From 42 to 72. That's about 60 lines of code. No, from 32, 30 lines of code. Let's move to EF7. This is the code that you need, okay? So if we want to go over the model,
41:22
the metadata of your entities, you just need to go to the DB context, ask for the model object. You can go and just iterate over all the entity types and each entity type, if you'll go here, exposes basic stuff like its type, its name,
41:42
the base type of the entity, allows you to fetch information about foreign keys, indexes, keys, properties, a lot simpler if you want to just scan over your metadata to understand the mapping between the database and your object. Okay, so if you look here, for example,
42:01
go ahead and type for each entity the CLR name and the SQL Server table name. So let's run this code. And to also allow me to talk a bit about the small change in EF Core when it comes to table mappings. It's creating the database right now,
42:20
so give it a second. Okay, so those of you in the front line, can you see the difference?
42:41
Take a second. Can you see the difference? It's the one character that is missing somewhere. The starship versus starships. There is a difference. Are you familiar with the pluralization of Entity Framework 6, right? Usually when it doesn't work, you're starting to get familiar with it.
43:03
Entity Framework 6 automatically tries to name the table as a pluralized version of your entity. So if my entity is a person, it will call the table people. If it's a starship, it will call it starships. Of course you can change the convention, but that's the convention. In EF Core, it has changed a bit.
43:22
At first they removed the pluralization entirely. So you will have got a person table and a starship table. In the latest version, the RC2 version, they again changed it a bit. And this time they didn't use pluralization. They just said, we won't name the table
43:42
after your entity type. We will name the table after your DBSet property. So in this case, for example, the reason that my person table is called actually people is because if you look at my DB context, you'll see that I have a people properties, okay?
44:04
But I don't have a starships property for the DBSet. That's why it took the entity type name, which is starship. Of course, you can use data annotations. You can use fluent API in order to select the name of the table.
44:22
You can, of course, inject your own logic on how to create table names. If you want to do this in, for example, German or French or whatever. Okay, Hebrew, God forbid. There are only a couple of companies in Israel that actually write table names in Hebrew. So it's supported, but you can't code against it, okay?
44:43
Because it's mixing Hebrew and English together and it changes from left to right to right to left text and just awful. Don't ever try to do that. And that goes to the Israelis that will watch this video afterwards. I'm guessing no one here actually writes in Hebrew. Okay, so this is one of the differences
45:03
between EF6 and EF4. So for your example, take that basic sample that we did before, and you run it on top of an existing database, that will probably won't work unless you name your properties exactly as the names of the tables, okay? No convention in EF7.
45:21
And that is one of the changes that you actually need to cope with. Next demo, extensibility of Entity Framework 7. And by the way, all the code that I'm showing you is already available on GitHub, but you'll need to wait for the end of the session to see the link, so don't go away.
45:43
Okay, so EF Core Services. Now what do we have here? So of course, there are a bunch of, it's called services in Entity Framework Core. The entire dependency injection, each type, each interface that is being ejected is known as a service.
46:02
There are about 150 services in EF Core when you use it with SQL Server. So I'm not going to show how to replace the whole 150, okay? I'm just going to show how to use one existing and how to replace an existing one. So first thing, in this code,
46:22
since I need to work with the dependency injection mechanism, I needed to add some code in order to create that options object because that options object also needs to manage the injection of the new types that I'm creating, okay? So if you're familiar with ASP.NET Core, it's the same types in EF Core.
46:42
So I'm using a service collection to manage the entire list of services. As I mentioned, the dependency injection, it uses components that are referred to as services. So I'm saying, well, I want to add Entity Framework SQL Server that will inject all the basic, the built-in types that match the different interfaces.
47:02
And then what I'm doing is I'm replacing the IBatch executor with my own custom executor. The batch executor is responsible for executing batch updates, batch inserts. And well, I won't override it because I have no idea how to write that code
47:21
that converts an entire list of entities into a batch update. I just hooked up to the existing one and did some stuff before calling into the next pipeline component. So we'll see that in a second. We can see that actually now, it doesn't do that much. Okay? What I'm doing here is I'm iterating
47:41
each of the command batches. So for example, if you needed to insert into multiple tables, you'll have more than one command batches. One batch is per entity type. And I'm just going ahead counting how many entities it's going to modify and what is the name of the table. And just printing out, you can use it for log files,
48:01
for performance and such to know exactly how much time it took to update say 50 entities in table X. So this is my batch executor. And what I basically do is just, you know, call the default batch executor, which I derive from. The second thing I'm using
48:21
is I want to use an existing service and hook up to that existing service and add my own stuff. And the service that I'm going to hook up to is the logging service. Entity Frank has built-in logging support and I can just hook up my logging components, log components, not log in, logging, I-N-G.
48:41
For example, you can log to a console window, to the debug window, to log format, entity, the event viewer, okay, wherever you want to log to. Don't log into the database because that will use SQL server to log and then it will log to SQL server and then you get an infinite loop of logging
49:00
and writing to the database. So what I have here is basically the same options builder from before, but now I'm telling it to use the SQL server and use that internal service provider that I used before. Okay, now I can, of course, when I add this implementation of the custom batch executor,
49:21
I can also add the implementation for my logging, but I want to show a different way of doing that and that is not adding that into all of your DB context, but adding it into a specific DB context. So you know how to hook up stuff into a specific DB context. So once you have the DB context, I can get that service provider from the context.
49:44
I can get the list of all the services. I am searching for a service called iLoggerFactory. That is the class that is responsible for creating the different log, logger objects. And I'm adding a new provider to that logger factory
50:01
for a console logger provider that I created. It's written right here. I will see that shortly. And I'm just specifying what is the minimum log level that I want to write to the console. I don't want to write everything, just information and above, okay? And I'm also adding an existing provider,
50:20
which is the debug output provider. This one I got from a NuGet package. Let me just open the packages here. I'll show you the name. Microsoft Extension Logging Debug, okay? That will output to the debug. You also have an event viewer, an ETW one, event trace and that sort of things.
50:41
So this is my own custom logging provider. You can see it here. It implements the interface. So it has a couple of stuff it needs to implement, such as create the logger itself, okay? So this is the provider and the logger is just down here. Basically what you need to do is just decide
51:01
if it's currently enabled according to the log level that is required right now and support the log method, which you get the log level, the event ID, of course, the state which contains the entire message and you get a formatter function here
51:20
from the backend that actually knows how to format and pull out information from that state object. So you can output it, you know, without understanding exactly what is that state object. So as you can see, what I'm doing here is I'm just changing the color of my output according to the type of the log level, okay?
51:41
Just so it will be interesting and using that formatter. So I want you to understand exactly how to replace that object to pull it the two string format or to pull one or another property from it. So I've added both providers and then I'm just doing stuff like, you know,
52:01
new person, add that person, save changes, that sort of stuff. Let me just take this time to also show you the save changes and how it works. So let's just run this. Well, I should actually run it in debug so you can see the debug output. But first of all, let's see those print outputs
52:22
to the console. Okay, so as you can see, this is all written in white. So this is the information stuff. I can see each of the SQL statements that are written, that are sent into SQL server, including by the way, this command, which is my insert command, okay?
52:40
The 10 inserts that I'm doing into the database. It's actually, let me see that. Oh, thank you. They finished earlier. We still have eight minutes. Okay, so this is the insert command. So insert circle or height and name into the table.
53:03
And here are all the values that I'm inserting into the database. As you can see, Skywalker number two, five, eight, and of course, all the numbers are here. And this is a single SQL statement. Okay, of course, it's a dynamic SQL statement, but it's a single SQL statement.
53:20
And of course, the entity from provider managers, all the stuff underneath the hood, such as, for example, if you're inserting 10,000 entities, it will break it down to, I think it will be two queries, 5,000 each. Okay, so it automatically knows how to do that. And if I also look for that batch executor,
53:41
here is the message, batching nine items into table people. Okay, so I probably did less than 10 instead of less or equal than 10. Let me just check that. Yeah, equal one, less than 10 instead of less or equal, so it's nine entities, not 10. Okay, bugs, you know, happens.
54:06
So let's run this again, this time in debug, so just so you'll see the debug output. Yeah, I think I should have opened the debug output first. Oh, yeah, see? Okay, so the same messages as you see in the console
54:22
are here now in the debug output, okay? So if you need to do that, just include the add debug in your code. The last demo incorporates a couple of samples, so both the data stores and the features and the platforms are all embedded into one sample,
54:40
so let's see that one. Let me just load that again because I unloaded this project. And the difference between this project and the previous ones, all of the others were just console application. This next sample is an ASP.NET Core example, okay?
55:00
So basically, since I'm running in ASP.NET Core, I should be able to run this code both on my Windows and on my Mac and on the Linux, if someone has one to give me, and any other type that knows how to run .NET Core. So the basic concepts of adding entity framework
55:21
into ASP.NET Core are the same as we've seen before. So what I'm doing here, I'm using add DB context and I'm setting the options, so I can actually inject a context with options into my ASP.NET controllers.
55:41
How many people are using ASP.NET in general? So just so I understand, if I say the word controller, everyone will understand what I'm talking about? Okay. So for example, if you look at my controller, you'll see that I'm asking for a context, a Star Wars context object. It will automatically be injected, including the options settings that I needed to have.
56:03
And that options is basically saying use SQL server with the following connection string, okay? Now, as you can see, I have another one here that I'll use shortly, which uses Postgres database instead of a SQL server database, okay?
56:21
Now, in my controller, as you can see, I'm doing all the simple stuff, such as eager loading, okay? I have here the option to add stuff here. So let me just run this once, get the database created. Hopefully it will work.
56:41
I'll drink a sip of water. We should see a list of all the entities that were added to the database. Basically means Luke Skywalker and Han Solo, each with their star ship, okay? So that basically worked.
57:01
The star ships didn't work because when I get all the people, I don't want to get all the star ships. So if I go to people slash one, I should get the star ships, okay? Let me just zoom in a bit. Now, first of all, this is ASP.NET Core.
57:22
So I should be able to run it on my Mac. We should see it shortly. I just want to show you something about the change tracking in Entity Framework. So let me just open up my Fiddler so I can post stuff into my service.
57:44
How many people are familiar with Fiddler? Fiddler? Okay. Anyone been to my Fiddler session in NDC in 2012? No? Okay. Just refresh that.
58:00
Okay, here it is. We want to do a post. Content type. Okay, I'll show this demo in the course platform one because we do need to wrap up things.
58:20
Okay, I'm going to add Chewbacca. Are you familiar with Chewbacca? Yeah, okay. So first let's use the people add person. Now this person has a star ship alongside it. So it's going to add the star ship, but that star ship already exists. Okay. So let's see what happens.
58:43
And we get the 404, of course, because it's without this one. Okay, we get the 400, which means it's my fault. And if I check the JSON content, basically it says cannot insert explicit value for identity column in star ship. I can't add a star ship with an existing identity that it has.
59:03
So probably add isn't the correct method to use because basically it says something in the comment, add assumes all the entities are new and it tries to edit using the existing ID that I got from the database before then. So let's try attach.
59:20
Okay, let's do this. And this is a spinet call, so I don't need to compile again. It actually compiles it just now. That's why it's taking some time. And come on, it takes a bit more to compile.
59:45
Come on. Seriously? We need to wrap up things, come on. Okay, so it might have formed.
01:00:00
on somewhere because I didn't use, yeah, I have try-catch here. Basically, let me just tell you what will happen. Nothing will happen because when you use attach, nothing not in the sense that it will get stuck like now, nothing in the sense that it just won't add anything to a database. Because using attach attaches the identity as unmodified. So if you use unmodified and you call save,
01:00:22
it looks at the object and says, well, it's unmodified. It won't save it. So nothing will be added. Let me just show you what I need to do. So first of all, using the state. Anyone use the entry option in EF6? Yeah? OK, so there is a bit of difference in EF6 and EF7.
01:00:40
In EF6, when I use entry for a top level entity which has references, in EF6, it will also set the state for its child entities, its related entities. In EF7, it won't. It will only set the state. It will only attach this single entity. So if I do added, what it basically will do,
01:01:01
it will add Chewbacca, but it won't update the starship. The actual way of doing what I want to do, add Chewbacca and change the ownership of the starship to Chewbacca, that will require me to iterate the object graph myself. But instead of iterating the graph and setting each state for each entity,
01:01:21
I can ask EF7 to use the change tracker API and just create a callback that will receive each and every one of the nodes in the graph and will allow me to investigate that node in order to specify what type of state
01:01:42
I want for that node. So I can add my own logic and say that if it's a starship and it has an ID, then it's modified. If it doesn't have an ID, then it was added. And if it's not a starship, then it was probably added, because it's that person. So for each type of insert that I want into database,
01:02:01
if I'm posting a new person or I'm posting a starship, I can change the logic of how to attach things into the entity graph. So this is the actual way to do that. And finally, I got the error. I can save now and try to run it again. But it will work. You can try that code later on. Just want to show you how to use that in Mac.
01:02:25
And let me just go to my Mac. And platforms, OK. So when you use a command line, you need to use .net. Let's restore packages.
01:02:44
Now, of course, I need to tell entity from which database to connect to. So let me just verify which database I'm connecting to here. So I'm connecting to a specific IP. So basically, my Mac will go to the SQL server
01:03:03
that is installed on my Windows machine. It's a virtual machine that I have on my Mac. So it restored all the packages, .net run. It's hosted. Let me go to localhost 5000 on my Mac, API, people, one.
01:03:33
And it works. It's actually connecting for my Mac to my PC. And let's see if Chewbacca was already added.
01:03:40
I don't think it was added because the attach didn't work before. Now, of course, as I showed before, I can also use other database providers. For example, I can install the Postgres NuGet package and use Postgres instead of that.
01:04:01
And that can actually also run on a database on my Mac. I don't need to have an SQL server for that. So if I, for example, go to my Postgres admin on my Mac and I use that provider, you will see the database being created on my Mac. So the provider also knows how to use Postgres databases,
01:04:20
whether they're on Windows or Mac or Linux, wherever. I see that no one is excited by the fact that Entity Framework works on a Mac. So I just want to, just two minutes about what's going to happen with Entity Framework 7. So first of all, there is a backlog
01:04:41
that still needs to be fixed for version 1. So for example, there still isn't lazy load in Entity Framework Core, which, I mean, come on. How am I supposed to work without a lazy load? Well, I'm going to pull the entire TTS on my own. So this has to be fixed. There isn't support for stored procedure mapping yet.
01:05:02
There isn't any support for data seeding yet. But those will get fixed. There is something really silly about EF Core that hasn't been fixed yet. If you have a many-to-many relationship, today with EF Core, you actually need to create a relation entity. So for example, if I had multiple starships per person,
01:05:22
and that starship can belong to different people, many-to-many, I should have added an entity, not a table, an entity for a person-to-starship object. That would have generated a person-to-starship table. So basically, I don't have many-to-many. I just have one-to-many relationships to TWO.
01:05:45
So this needs to be fixed so we can actually map end-to-end relationships in the database. Of course, they will also support inheritance mapping other than the table pre-hierarchy. In EF6, we have table per type and table per concrete type.
01:06:00
This hasn't been implemented in EF Core. And of course, command interception, which we now have in EF6, still doesn't exist in EF Core. So as you can see, it's still not an entirely EF6-equivalent solution in EF Core. So in progress for version 1, bug fixing, of course,
01:06:21
performance improvements, documentation which is lacking. And just to sum things up, what was thrown out, as I mentioned before, there is no EDMX support anymore. If you use entity SQL, the dynamic SQL-like statements, that also out. And of course, object context API is gone.
01:06:42
God bless them. So relation between EF Core and EF6. EF Core is still the right way to go for new projects. Unless, of course, you need some specific stuff from EF7, like the support for .NET Core and such.
01:07:02
As you've seen, some features are still missing. Some code is still not mature enough. Not all the link support has been added. But it's on its way. So moving from EF6 to EF Core, it's not just upgrading the local packages. It's an entirely new engine.
01:07:22
It has different behaviors, like the change tracking that I explained before, like the conventions for pluralization and such. So beware of those changes. Test your code if you're going to just update it to Entity Framework 7. So if you want to use Entity Framework 7,
01:07:40
if it's something simple, like something that just needs to edit a table, a simple web API sort of stuff, then you can use Entity Framework Core. No problem with that. Stuff will still work in the RTM. There aren't going to be that many changes. But if you are targeting .NET Core, ASP.NET Core, the universal Windows platform, or whatever it's called.
01:08:04
I'm not a client person, so I don't know what it's called, actually. If you're aiming at Xamarin, if you're aiming at any of those different types of frameworks that are not the full data frameworks, then EF Core is the only way for you right now. So just go ahead and pray for the gods
01:08:22
that they won't change everything in v1. So where do you go from here, aside from your next session? There is a link to the documentation here. And at the bottom, you can see the link to my demos. You can go on ahead and check, I skipped two demos that show two features that are called shadow
01:08:41
properties and alternate keys. You can see those in the platform demo. Basically, shadow properties is using properties that are not in the entity table, not in the entity object, but are in the table itself. So you can pull data from the table, but not showing in the object.
01:09:00
And alternate keys is just adding new unique indexes into the table by saying, for example, the name of the person is also a unique key. So it's an alternative key. And that's it. Enjoy the rest of the conference. And if there are any questions, I'm here.
01:09:22
Thank you.