In this episode, I talk with Julie Lerman about the Microsoft Entity Framework. We discus what it is and why you should use it. We talk about the Cosmos DB provider, EF Core and new features.
[00:00:39]
Unknown:
This week on developer weekly. But an important thing to understand is that document database is still very different from a relational database. So I don't think people should just blindly say, well, I've been using Android framework for years with SQL Server or SQL Lite. So I'm just gonna flip over to Cosmos DB.
[00:01:01] Unknown:
Hey, guys. I've been using Windows 10 for years now, and I recently took the time to learn how to be more productive with it. There are lots of shortcuts and tools in Windows 10 that help me throughout the day. Do you also want to be more productive with Windows 10? Then check out my new Udemy course called Windows 10 Productivity Booster. You can check it out at azureberry.com/windows. That is azureberry.com/windows. Welcome to another episode of Developer Weekly. This week, I'm talking with Julie Lerman about the Entity Framework. Julie is a Microsoft Regional Director, Docker Captain, and a longtime Microsoft MVP who now counts her years as a coder in decades.
She makes her living as a coach and consultant to software teams around the world, and amongst other things is a book and Pluralsight author. Welcome, Julie. How are you doing? Hi, Barry.
[00:01:59] Unknown:
Oh, you know, considering, COVID times, I I'm doing relatively well. Everybody's healthy. My family is okay. And, we talked already a little bit about the fact that I live in a very rural place. Mhmm. So I'm not quite as restricted as, you know, we're we're not quite as restricted in in ways as a lot of peep other people I know are. So and, you know, I've been kinda locked at home, so I've been working a lot on my Pluralsight courses. Have have you been knocking out your courses also?
[00:02:40] Unknown:
Yeah. It's like the upside of not have, being able to travel, basically. Yeah. Yeah. I thought that all the time. Takes a lot of time. So Yeah. Yep. In December, for instance, I created lots of, courses for Azure certifications because ProLabsite did a big push for, Azure certification courses. Yeah. So I created 5 of them, I think, and lots of other other offers there too. Yeah. Those are smaller courses, but they're very valuable if you're taking the actual certification.
[00:03:10] Unknown:
Oh, yeah. And, you know, interestingly, one of the things I did was I went back to some old courses of technologies that are still widely used. Mhmm. For example, you know, we're gonna be talking about Entity Framework Core, the latest version, but the predecessor to Entity Framework Core, and we'll talk about that in a minute, but it was just called Entity Framework. And the last version of that family, not family, but which, I'm not sure how to even say that. I should come up with a word. The last version of that is still in use by millions of applications. Yeah. So I went back to these courses that were, you know, like, 4 or 5 years old. And I didn't fully update them, but I just made sure they were relevant so that, you know, some of the tweaks and little things that have happened and evolved with that older version, you know, people would be aware of them even if they're watching the old course. And and also, you know, mention of the fact that since this course was published or, you know, we've also gotten EF Core, and you might, you know, be using that, so go watch this course instead. So I did a I did a lot of that, like, you know, the kind of stuff you don't really normally have time to do. But, you know, really went through it and and, you know, identified places in there that really just needed a little more explanation for, you know, where where things stand currently. So that was that was an interesting thing to do. I don't think a lot of people are watching it, but I just wanted to make sure it was still there yet relevant to people who are needing to watch it now instead of, you know, when I first created it. Yeah. That was that was an interesting
[00:05:04] Unknown:
thing to do. It's good to have time for for things like that.
[00:05:08] Unknown:
Yeah. Yeah. Because we we always wanna move forward, learn new things, share new things. Right? And and whoever wants to look backwards. Yeah. Exactly. So yeah.
[00:05:19] Unknown:
And you have been creating, content for the entity framework for a very long time now. Right? How did you even get involved with the entity framework in the first place?
[00:05:30] Unknown:
Well, it it's a funny story. I'd always been interested in data access, not so much managing databases. I'm you know, I I rely on people with much more expertise to do DDA and and design databases and things like that. But, you know, even, back in the eighties when I was building software, I I always was interested in in that aspect of it. And using some of these old applications like Access and FoxPro and and things like that. So I'd always been interested in, you know, the tools that let us get data in and out of our applications and had worked with, Microsoft Teams and written about even ADO, right, from VB. Remember visual basics? Yeah. Yeah.
And and then, ad0.net when dot net came out. So I've been, you know, exploring those and writing about them and and having interactions with the team. So Entity Framework, is an object relational mapper. So this was, Microsoft actually had Entity Framework was their 3rd bat at creating an object relational mapper or ORM, we call it. And I'd never used an ORM before, and I hadn't really paid much attention to the first two. Good thing, because they never got released. So I got invited to a just a very small with, like, you know, 4 people, little gathering at TechEd in 2,006 where some of the people who'd been working on, ADO.
So entity framework, this this ORM had been something that was coming out of Microsoft Research. And so then it had got passed over to the people who were involved with ADO and and ad0.net. So they were showing that to me and a few other people, and I thought, oh, that's cool. Because especially because I'd never seen an ORM before and and kind of the the, things that it does. And I'll I can explain that. I'll I'll finish this story and then explain what Yeah. It is about an ORM. So, I I was just like, oh, this is cool. And and, most other people in the dot net world kinda looked at it and said, yeah. They already tried twice that, you know, this it's not gonna get released. I was like, well, whatever. This is this is kinda cool and interesting. And because everybody was ignoring it, I was really doing all this discovery. And that was a lot of fun too, knowing the things that I'm sharing with peep with people were things that I figured out all by myself. You know? Not that there was no docs. There was nothing written.
So I was getting more and more to be, like, the person who was, learning about and sharing and understanding Entity Framework. Well, as luck or whatever would have it, Microsoft eventually released entity framework and said, this is now the way you should be interacting with data from your dot net applications. And all of a sudden, that put me in the position of being the worldwide expert on the topic only because nobody else had paid any attention to it. So, but that was so there have literally been which is it took some effort to to actually realize this. There's been 8 releases, like, full releases of entity frameworks since 2008.
And the reason it was it was hard to come up with that number, it was the first last week was the first time I actually thought about this. It's because, they didn't just consecutively number them. And then when they made that big switch from entity framework to entity framework core, they went back to 1 again. So, yeah. So, you know, anyway, across these 8 versions, I've just always been interested in, you know, seeing how much better it's getting and then sharing that with people. And I I'm still still doing it. So I've written, 4 I wrote 4 books on entity framework. I'm not writing books anymore. There is so much work and things things are evolving so quickly. It's just really hard. It's hard enough to keep up with Pluralsight courses as it you know, to do with a book. So, you know, writing articles and doing Pluralsight courses and, you know, and then, like, the the coaching and and mentoring and things like that as well.
[00:10:32] Unknown:
Right. So oh, that's an, that was your way to become the entity framework, leader of the world. I I've tried that with Azure as well, but it didn't really work because lots of people were doing Azure. Yeah. Well, that's the problem because people, there are people who have said, oh, I wanna be the Julie Luhrmann of Technology X. Mhmm. Right? But,
[00:10:54] Unknown:
you know, it was just really, some kind of good fortune for me. Right? Because everybody had ignored it. Right? And every, you know, so now somebody wants to be the go to person for tech you know, some technology, but, unfortunately, those technologies are so interesting. You're you're not the only one digging into it.
[00:11:17] Unknown:
Yeah. But it's not only, only luck, of course, of timing. It's also showing up every time to actually share that knowledge to the world. Yeah. Yes. Of course. So it's definitely also a good work on you and, you know, just a good thing that you did to make yourself into this And being foolish at the start. Right? Well, you know, oh, they're not gonna release it. I'm like, whatever. It's cool. It's fun. I'm learning. I'm enjoying myself. Right? That's what it is. So you're learning and you're having fun. So
[00:11:45] Unknown:
Oh, that was that was the dog shaking his head with his big floppy ears. In case you're wondering. Yeah. My office mate. So we should probably talk about what, an ORM is and what this thing, entity framework is. Exactly. What what can you do with entity framework? Well, I'll I'll just back up and again just say, you know, an ORM is an object relational mapper and it the goal of an ORM is to solve that problem of the fact that, you know, this it it changed the story changes a little bit with all our document DBs and NoSQL and everything. But if you're thinking about relational databases, solving that problem of the fact that the data is stored in, you know, structured rows and columns, right, in this very organized way.
But in our applications, we have objects, and objects don't necessarily match the rows and columns, and the relationships don't necessarily match the constraints between tables in your database, etcetera. So, we spend a lot of time writing SQL, creating connections, creating commands, executing the commands, getting back the results, transforming the results into our objects. And then when it's time to update things, again, you know, identifying what's changed, writing SQL, sending that SQL to the database, maybe getting back, newly generated primary keys from the database. Right?
So there's so much redundant work around that, and what an ORM does is it it allows us first to create a mapping between our objects and the database schema, and it takes care of creating the commands, creating the connections, executing the commands, transforming the results, transforming changes into update commands or insert commands and executing them, etcetera, etcetera. Right? So all this boilerplate code in a way, but but it's not really because, you know, who knows what kind of query you're gonna be sending. Right? So the ORM has to be smart enough underneath the covers to understand how to transform a query or to understand what data has changed and, therefore, what kinds of commands need to be sent to the database.
So there's a lot of that logic in the ORM. And then, one really interesting thing that's very different about entity framework, most ORMs have a 1 to 1 mapping. So the object your classes, your objects look the same as your the tables in your database. Mhmm. Right? It just matches the schema. The column names match, etcetera. So Entity Framework actually doesn't depend on there being this direct relationship between them. Instead, it has this mapping layer. Part of that's determined just by defaults. It's called, convention over configuration.
So there's con some conventions, assumptions about how things will map. Mhmm. But then there's an entire library filled with possibilities to trans to change or or redefine those mappings. So we have a whole all these APIs to ex to describe, how we really want those objects to map to the schema in ways that will override those those defaults. Mhmm. So there's a lot of creativity in there, so you don't depend on that one to one relationship. So what's really nice about that is you're not you're not kind of not I don't wanna say forced to, but, you're not in a position where the way you have to design your applications Matt has to match the database. Yeah. Right? It can be you could design it the way that you need to design it to solve the problems you're solving, And then thanks to all the creative ways that the API lets you, describe how to go back and forth between the, schema of your objects and the schema of the database, lets you make, you know, make that flow through.
Yeah. So that's that's one of the big big differences, about entity framework. And then, you know, another really interesting advantage of that is that you don't have all of your developers writing their own ways of doing things or having to comply with, you know, remember the rules of how we're gonna do connections and commands and all of that. Like, Entity Framework has its way of doing that. Another thing that I haven't mentioned yet is that entity framework can't, when it comes to transforming into SQL or taking results and reading those results and and transforming them back, It really has to have a good understanding of the database itself, not just the schema, but how the database works. Yeah. So entity framework does the bulk of it, but then we have providers, some written by Microsoft, but many written by third parties, or even the owners of the providers.
So providers that have specific knowledge about kinda that last, transformation. Right? That last connection between entity framework any frameworks capabilities and the database. So, there's many, many, providers, and some some they're duplicates for. So for example, Microsoft has created a provider for SQL Server, surprise surprise. Mhmm. And, SQLite. And, and believe it or not, Cosmos DB, which isn't even a relational database.
[00:18:16] Unknown:
Yeah. But that, it it does work with, document databases as well. Right? Because, the problem that you were just talking about to translate tables with rows and columns into objects, that is one thing that it does. But then another problem that it solves is, to get rid of all the boilerplate code to Exactly. Exactly. To all the SQL and to connect to the database and to transform whatever data that is into objects. So Yeah. It does that also with Cosmos DB, for instance. Right?
[00:18:45] Unknown:
Exactly. So, you know, people are like, well, why would I do that? And the real answer to that is if you already have expertise with entity framework, it makes sense to say, well, why don't I just, you know, use that same logic and code that I already know how to do? So, for example, you know, I still wanna just be able to write a link query. So for those of you who might be not familiar with LINQ, LINQ is a query language within dot net, within the dotnet languages. Yep. So, you know, c sharp and and Visual Basic and f f sharp. So it's a really nice query language that lets you write queries, with your, you know, dot net objects.
And then it's actually used throughout dot net. Right? Like, that's the cool thing. There's a lot of you don't this isn't just for entity framework. It's just for in memory objects. However, Entity Framework has an extension of link that knows how to do what link knows how to do in terms of, translating those queries and then takes it to that next step, which is then translating it into SQL. So if we already know how to do all that and know how to execute the queries and know how to trigger the interaction with the database to happen with Entity Framework, there were so many people that said, can't you know, can't I just use Entity Framework to interact with Cosmos DB instead of having to learn a whole another, API or, you know, because there's dot net APIs and JavaScript APIs, etcetera, to do it. Yeah. I think that's also a good idea because it's like a standardized
[00:20:36] Unknown:
abstraction that most dot net developers know by now, the entity framework.
[00:20:41] Unknown:
But an important thing to understand is that document database is still very different from a relational database. So I don't think people should just blindly say, well, I've been using Entity Framework for years with SQL Server or SQLite, so I'm just gonna flip over to Cosmos DB. Right? You need to understand how Cosmos DB works. You need to understand how EF Core works with it. Right? Instead of just just using it. And and what would you do different than, for instance?
[00:21:11] Unknown:
Would you design the entities and the mappings differently?
[00:21:14] Unknown:
Well, the the mapping API is, a little different. But the other the other thing to be considerate of, and I I you know, look. I'm I'm not telling you because I'm sure you're very familiar with Cosmos DB, but, just, you know, thinking about what goes into a collection, what what you know, how you're gonna shape all of that Right. Information and how Entity Framework responds. So for example, if you have relationship, maybe, well, the ease the easy one that micros any framework teams use is a blog with posts. Right? The one to many relationship. If you have a one to many relationship like that, the the way that Entity Framework is going to persist it by default is it's gonna create a collection for blog, and it's gonna create a separate collection for posts.
Right. Right? Yep. They're not a document because posts have their own identity identity. However, if you use the feature of Entity Framework Core called owned entities, which lets you define essentially your a complex type that is used as a property of another entity. Right? So it doesn't have its own identity. It's like, you know, just it's it's just a it's another type, but it's it's not an entity. That, by default, will get stored as a a sub document. Right? Because it's a it's just a property, but it's a property with its own set of properties. So those kinds of things. And how how that works by default as understanding how it works by default, understanding what you can change, understand the impact of the default or the changes, especially, not just on performance, but on pricing.
Yeah. Right? Collection. So it that that's why I wanna make sure you know, whenever I do talk about the fact that, oh, yeah. You can use the Cosmos DB provider Yeah. That people are aware that, you know, they should not just start using it without understanding how Cosmos DB works, how the storage works, how the pricing works, and how Entity Framework interprets things. I love doing that, though. I love debugging. I love doing experiments and tests, and not just test to make sure my, you know, unit tests, etcetera, to make sure my logic works, but I love exploring to see what, you know, what does entity framework do when I do this? What does it do when I do that? Right? I love I love that kind of debugging. Yeah.
Just but that's how I learn it. Right? That's how I learn it. And then, you know, sometimes there's surprises.
[00:24:04] Unknown:
Okay. That is very, good to know that, to be mindful when you, for instance, use a different provider. I've also noticed this when I started using the Cosmos provider as well. The Entity Framework has been through a lot of versions. Like you said, there's this family of what's called the Entity Framework, and then the newer family is what's called Entity Framework Core. This is where it gets a bit complicated because now with dotnet5, we lost the core moniker, at least for dotnet. But then other things like asp.net is still called asp.netcore.
And then entity framework is also still called entity framework core. Right? Entity framework core 5 point o. Yeah.
[00:24:48] Unknown:
And and I think that was a really good decision. The reason is because there's such a disparity between the original entity framework and entity framework core, especially when it comes to things like the fact that EF Core is cross platform. Yeah. Right? EF Core is where all of the innovation is going into, etcetera. But there's still, you know, people who still, like I said before, still have entity framework 6 in their applications, and there's no compelling reason to just switch it to EF Core. Right? It's working. Those applications really aren't, doing much in terms of evolving.
They're just they are working, churning away, doing their Yeah. Doing their work. So I think it's really important to have a really clear delineation between the old entity framework and the new EF Core. And so I think it was a good idea that they they kept Core on it instead of dropping it when dot net did. Because with dot net, dropping dot net you know, dropping core, we we were still we can still differentiate because the old dot net is really dot net framework. Yeah. Yeah. Right? It has that. Right? Unfortunately, entity framework has framework in both of its names. Yeah.
Right? So, like, what were what would they they would have to literally call it in order to really match, they would just have to call it entity. I don't think that would work. No. That would work. Alright. It's funny. I hadn't thought of that before.
[00:26:37] Unknown:
So with, with dot net Framework 5.0, the Entity Framework Core Entity Framework Core 5.0 was also released with lots and lots of new features. Like, if you look at Holy smokes. Microsoft docs to their website, there's this article of what's new in Entity Framework core 5 point o, and that's a 41 minute read. That's that's crazy.
[00:26:59] Unknown:
Can you maybe highlight a couple of The team didn't have to write the team didn't have to write that all at once because Yeah. Yeah. The way they broke it the way they break it down is, they had 8 previews because they really, you know, just like dotnet does andasp.netcore does, they really engage the community in, you know, they do these preview releases, and, a lot of people will use it and hammer on it and give feedback. Yeah. So, so it you know, preview 1, 2, 3, 4, 5 through 8, and then release candidate, and then they released it. So, yeah, it's, they oh, I'm trying to think there this was before it was released early on, somebody from the team had blogged. Oh, it's Arthur Vickers who's, like, the lead on the team.
And he and this was still I think it was still in one of the previews, and he tweeted that there were there were already 637 GitHub issues closed. 299 bugs had been fixed. 225 feature new features and minor enhancements, and a 113 were docs, you know, cleaning up the docs. So, you know, interestingly, that was another really big push for them with EF Core 5, was making the docs better and better and better. Not just, showing syntax for things, but showing, you know, oh, if you're, using, Blazor. Right? This is a really good this here's an approach we would recommend, like, how you would, blend entity framework, weave entity framework into your application. Right? So guidance.
Yeah. That's why I don't need to write books anymore. The docs are kidding. The docs are so good. So that's that you know, they worked really, really hard on the technology, but then they, you know, turned around and really made the documentation an important focus as well. And and they're still working on that right now. But, yeah, that was that was, a really big deal. So a couple of the really interesting things that came to us in EF Core 5, and I'll just back up and explain that when they made the leap from e entity framework, the last version of entity framework is 6, although they've made some tweaks to it over the years, and now it's 6.4. Mhmm. But when they they went to EF Core, they rewrote it from scratch.
Right? They they're sayings, basically, you know, it's gonna work just about the same, but they were they felt that they were really stuck with this very old code base that had been basically created in, like, 2006. So they wanted to rewrite it from the ground up using modern software practices and also getting rid of a lot of the kind of code that was in there that was just locking them and blocking them from, evolving in directions that they wanted to go. Yeah. So because it was a, you know, a a replacement, there was no way they could get all the features that, you know, EF 6 had come a long way. Right? And and it was really evolved, and it was very feature rich. And there was no way they could get all the same features into EF Core as people were used to at EF 6. So they focused on, you know, the most used stuff, the most you know, that's that that's how they prioritized. Right? The the stuff that most people are using.
And then over time with EF Core, they're trying to they're bringing in more and more of those, features. Like, they're they refer to that as parity with with EF 6, to bring more and more of those features in. And, you know, there are some of these features that maybe not not a lot of people use, but to the people who use them, they're really important. Yeah. Yeah. Some of the ones that were missing features that had been driving some people just you know, they were just so frustrated. They're like, we still you know, we cannot use EF Core until it has these features. We can't switch over until it has these features.
But, again, you know, they weren't as critical to the bulk of people using it. One of them was many to many, supporting many to many relationships between, between entities, and that came back so we had a kind of a a, there was a way to do it starting with the f core, but it wasn't as simple. We didn't have what we refer to as the skip navigation. So that means, you know, if you've got, let's go back to blogs. So you might have a a blog that has multiple authors. Right? And then some of those authors might be writing in a variety of blogs.
Yeah. So the skip navigations would mean that in the blog object or the blog class, you just have a a property that's a list of authors. Right? A collection list of authors or collection of authors. And in the author class, you have a list of blogs that the author writes for. And the Entity Framework under the covers figures out that that is a many to many relationship. And in a relational database, you need to have a join table to track, you know, author number 1 writes for blog number 3. Author number 2 also writes for blog number 3. Author number 1 also writes happens to write for blog number 17. Right? So just that that join entity.
So the way that worked in old entity framework, that part was really nice. But if you wanted to do anything else a little more creative, hey. When did that author start writing for the blog? Then the whole thing breaks, and you had to actually, do set up the relationship manually. Entity Framework couldn't just magically figure it out under the covers. So they didn't want to just duplicate that. They really needed to think about it and also set Entity Framework up, do some things inside of entity framework to support a better way of having many to many so you weren't limited when you were using it. And they finally achieved that with some, some work that they did in entity framework core 3 that was maybe not visible to people using it, but it was, you know, kinda foundation stuff. And then they finally were able to do that with EF Core 5. And so EF Core 5, we have this really simple way of skip navigations just working, but there's also a lot of other very creative things you can do with it.
And what's happening under the covers isn't magic, right, that that you can't do anything with. It's there's a lot of really solid stuff, really fascinating stuff underneath the covers that's happening. So that was a a a really interesting and kind of a flagship feature that came into EF Core 5 that gave us more parity with e, entity framework. And, you know, there's there's some other things like that. But that reasoning of, you know, yes, we implemented it, you know, back in 2006, but the way it was implemented, we don't want to just duplicate that because there's a lot of problems with how that was written back then. Right? So there was a lot of things that they set up this foundation for, and then they were able to finally achieve it in EF Core 5. So so that's been really, really cool. Plus, it's just getting, you know, better and better and better. Right? As more people use it, they run into walls that prevent them from doing things the way they want to, and they, you know, the everything's very transparent, and the team responds to that, and they just, you know, make more and more improvements.
[00:35:42] Unknown:
Yeah. It just, it just keeps on going, which is great. Yeah. Which exactly.
[00:35:47] Unknown:
Instead of just throwing it out and starting all over again, say, oh, you know, we wanna do it differently. Like, they're really invested in it. Yeah.
[00:35:58] Unknown:
And, so there that's one. There are a lot more new feature. Is it something that you, also cover in one of your Pluralsight courses?
[00:36:08] Unknown:
Yeah. So, I have 2 courses about EF Core 5. 1 was actually a Webeter that I did that they published, and it's, I think, it's, like, an hour and a half long, and, it's called, I don't know, something like, moving from EF Core 3 to EF Core 5. It you know, it's it's what it could cover in in an hour or so. And it's really aimed at people who are using EF Core 3, so they understood about EF Core 5. One of, I think, you know, besides the many, many, many, many changes, one of the really important things to understand about moving from EF Core 3 to 5 is especially for those who moved from EF Core 2 to EF Core 3, EF Core 3 is what I refer to as the breaking changes edition. That was when they said, we're just focusing there weren't a lot of new features. They were focusing on really making the foundation really, really solid, and then they were able to do so much to, you know, to add on in EF Core 5 because of that.
So, peep it was such a big deal how much breaking changes there were. Very well documented, very well explained, each and every one. Anyway, a lot of people were worried that that was gonna happen again. Right? But, I mean, that was a sea change, right, to EF Core 3. So EF Core 5 does not have that slew of breaking changes. And then the other course that I have is, just a not just a. It's a getting started course. So, it's a great review for people who already use entity framework Core or Entity Framework to just get a feel for some of the stuff that's in EF Core 5, but it's also good for people who've never used entity framework at all before. Right? So for so the people who've used EF Core 3 maybe and are just kind of looking to see what's different, they might watch it a little more quickly and then go, oh, wait. Here's here's something that's a little different.
But it's not a a clear, you know, list of what's changed because it's really more aimed at, people who are just starting with entity framework. They've never used it before.
[00:38:32] Unknown:
Okay. That's great. I'll, link to those courses in, the show notes and also to, your blog when people can find you there as well.
[00:38:40] Unknown:
Awesome.
[00:38:41] Unknown:
Alright.
[00:38:42] Unknown:
Thank you very much for being on the show. Oh, Barry, it was a pleasure. Thanks for inviting me. Alright. And, you know, I always love to talk about entity framework.
[00:38:53] Unknown:
I know. Alright. Thank you very much. And this has been another episode of Developer Weekly. We'll talk to you next week. Could you please go to rate this podcast.com slash developerweekly and rate this podcast and leave a review? This helps me to spread the word about the podcast and helps other people to find it. That is rate this podcast.com/developerweekly. Thank you so much.
This week on developer weekly. But an important thing to understand is that document database is still very different from a relational database. So I don't think people should just blindly say, well, I've been using Android framework for years with SQL Server or SQL Lite. So I'm just gonna flip over to Cosmos DB.
[00:01:01] Unknown:
Hey, guys. I've been using Windows 10 for years now, and I recently took the time to learn how to be more productive with it. There are lots of shortcuts and tools in Windows 10 that help me throughout the day. Do you also want to be more productive with Windows 10? Then check out my new Udemy course called Windows 10 Productivity Booster. You can check it out at azureberry.com/windows. That is azureberry.com/windows. Welcome to another episode of Developer Weekly. This week, I'm talking with Julie Lerman about the Entity Framework. Julie is a Microsoft Regional Director, Docker Captain, and a longtime Microsoft MVP who now counts her years as a coder in decades.
She makes her living as a coach and consultant to software teams around the world, and amongst other things is a book and Pluralsight author. Welcome, Julie. How are you doing? Hi, Barry.
[00:01:59] Unknown:
Oh, you know, considering, COVID times, I I'm doing relatively well. Everybody's healthy. My family is okay. And, we talked already a little bit about the fact that I live in a very rural place. Mhmm. So I'm not quite as restricted as, you know, we're we're not quite as restricted in in ways as a lot of peep other people I know are. So and, you know, I've been kinda locked at home, so I've been working a lot on my Pluralsight courses. Have have you been knocking out your courses also?
[00:02:40] Unknown:
Yeah. It's like the upside of not have, being able to travel, basically. Yeah. Yeah. I thought that all the time. Takes a lot of time. So Yeah. Yep. In December, for instance, I created lots of, courses for Azure certifications because ProLabsite did a big push for, Azure certification courses. Yeah. So I created 5 of them, I think, and lots of other other offers there too. Yeah. Those are smaller courses, but they're very valuable if you're taking the actual certification.
[00:03:10] Unknown:
Oh, yeah. And, you know, interestingly, one of the things I did was I went back to some old courses of technologies that are still widely used. Mhmm. For example, you know, we're gonna be talking about Entity Framework Core, the latest version, but the predecessor to Entity Framework Core, and we'll talk about that in a minute, but it was just called Entity Framework. And the last version of that family, not family, but which, I'm not sure how to even say that. I should come up with a word. The last version of that is still in use by millions of applications. Yeah. So I went back to these courses that were, you know, like, 4 or 5 years old. And I didn't fully update them, but I just made sure they were relevant so that, you know, some of the tweaks and little things that have happened and evolved with that older version, you know, people would be aware of them even if they're watching the old course. And and also, you know, mention of the fact that since this course was published or, you know, we've also gotten EF Core, and you might, you know, be using that, so go watch this course instead. So I did a I did a lot of that, like, you know, the kind of stuff you don't really normally have time to do. But, you know, really went through it and and, you know, identified places in there that really just needed a little more explanation for, you know, where where things stand currently. So that was that was an interesting thing to do. I don't think a lot of people are watching it, but I just wanted to make sure it was still there yet relevant to people who are needing to watch it now instead of, you know, when I first created it. Yeah. That was that was an interesting
[00:05:04] Unknown:
thing to do. It's good to have time for for things like that.
[00:05:08] Unknown:
Yeah. Yeah. Because we we always wanna move forward, learn new things, share new things. Right? And and whoever wants to look backwards. Yeah. Exactly. So yeah.
[00:05:19] Unknown:
And you have been creating, content for the entity framework for a very long time now. Right? How did you even get involved with the entity framework in the first place?
[00:05:30] Unknown:
Well, it it's a funny story. I'd always been interested in data access, not so much managing databases. I'm you know, I I rely on people with much more expertise to do DDA and and design databases and things like that. But, you know, even, back in the eighties when I was building software, I I always was interested in in that aspect of it. And using some of these old applications like Access and FoxPro and and things like that. So I'd always been interested in, you know, the tools that let us get data in and out of our applications and had worked with, Microsoft Teams and written about even ADO, right, from VB. Remember visual basics? Yeah. Yeah.
And and then, ad0.net when dot net came out. So I've been, you know, exploring those and writing about them and and having interactions with the team. So Entity Framework, is an object relational mapper. So this was, Microsoft actually had Entity Framework was their 3rd bat at creating an object relational mapper or ORM, we call it. And I'd never used an ORM before, and I hadn't really paid much attention to the first two. Good thing, because they never got released. So I got invited to a just a very small with, like, you know, 4 people, little gathering at TechEd in 2,006 where some of the people who'd been working on, ADO.
So entity framework, this this ORM had been something that was coming out of Microsoft Research. And so then it had got passed over to the people who were involved with ADO and and ad0.net. So they were showing that to me and a few other people, and I thought, oh, that's cool. Because especially because I'd never seen an ORM before and and kind of the the, things that it does. And I'll I can explain that. I'll I'll finish this story and then explain what Yeah. It is about an ORM. So, I I was just like, oh, this is cool. And and, most other people in the dot net world kinda looked at it and said, yeah. They already tried twice that, you know, this it's not gonna get released. I was like, well, whatever. This is this is kinda cool and interesting. And because everybody was ignoring it, I was really doing all this discovery. And that was a lot of fun too, knowing the things that I'm sharing with peep with people were things that I figured out all by myself. You know? Not that there was no docs. There was nothing written.
So I was getting more and more to be, like, the person who was, learning about and sharing and understanding Entity Framework. Well, as luck or whatever would have it, Microsoft eventually released entity framework and said, this is now the way you should be interacting with data from your dot net applications. And all of a sudden, that put me in the position of being the worldwide expert on the topic only because nobody else had paid any attention to it. So, but that was so there have literally been which is it took some effort to to actually realize this. There's been 8 releases, like, full releases of entity frameworks since 2008.
And the reason it was it was hard to come up with that number, it was the first last week was the first time I actually thought about this. It's because, they didn't just consecutively number them. And then when they made that big switch from entity framework to entity framework core, they went back to 1 again. So, yeah. So, you know, anyway, across these 8 versions, I've just always been interested in, you know, seeing how much better it's getting and then sharing that with people. And I I'm still still doing it. So I've written, 4 I wrote 4 books on entity framework. I'm not writing books anymore. There is so much work and things things are evolving so quickly. It's just really hard. It's hard enough to keep up with Pluralsight courses as it you know, to do with a book. So, you know, writing articles and doing Pluralsight courses and, you know, and then, like, the the coaching and and mentoring and things like that as well.
[00:10:32] Unknown:
Right. So oh, that's an, that was your way to become the entity framework, leader of the world. I I've tried that with Azure as well, but it didn't really work because lots of people were doing Azure. Yeah. Well, that's the problem because people, there are people who have said, oh, I wanna be the Julie Luhrmann of Technology X. Mhmm. Right? But,
[00:10:54] Unknown:
you know, it was just really, some kind of good fortune for me. Right? Because everybody had ignored it. Right? And every, you know, so now somebody wants to be the go to person for tech you know, some technology, but, unfortunately, those technologies are so interesting. You're you're not the only one digging into it.
[00:11:17] Unknown:
Yeah. But it's not only, only luck, of course, of timing. It's also showing up every time to actually share that knowledge to the world. Yeah. Yes. Of course. So it's definitely also a good work on you and, you know, just a good thing that you did to make yourself into this And being foolish at the start. Right? Well, you know, oh, they're not gonna release it. I'm like, whatever. It's cool. It's fun. I'm learning. I'm enjoying myself. Right? That's what it is. So you're learning and you're having fun. So
[00:11:45] Unknown:
Oh, that was that was the dog shaking his head with his big floppy ears. In case you're wondering. Yeah. My office mate. So we should probably talk about what, an ORM is and what this thing, entity framework is. Exactly. What what can you do with entity framework? Well, I'll I'll just back up and again just say, you know, an ORM is an object relational mapper and it the goal of an ORM is to solve that problem of the fact that, you know, this it it changed the story changes a little bit with all our document DBs and NoSQL and everything. But if you're thinking about relational databases, solving that problem of the fact that the data is stored in, you know, structured rows and columns, right, in this very organized way.
But in our applications, we have objects, and objects don't necessarily match the rows and columns, and the relationships don't necessarily match the constraints between tables in your database, etcetera. So, we spend a lot of time writing SQL, creating connections, creating commands, executing the commands, getting back the results, transforming the results into our objects. And then when it's time to update things, again, you know, identifying what's changed, writing SQL, sending that SQL to the database, maybe getting back, newly generated primary keys from the database. Right?
So there's so much redundant work around that, and what an ORM does is it it allows us first to create a mapping between our objects and the database schema, and it takes care of creating the commands, creating the connections, executing the commands, transforming the results, transforming changes into update commands or insert commands and executing them, etcetera, etcetera. Right? So all this boilerplate code in a way, but but it's not really because, you know, who knows what kind of query you're gonna be sending. Right? So the ORM has to be smart enough underneath the covers to understand how to transform a query or to understand what data has changed and, therefore, what kinds of commands need to be sent to the database.
So there's a lot of that logic in the ORM. And then, one really interesting thing that's very different about entity framework, most ORMs have a 1 to 1 mapping. So the object your classes, your objects look the same as your the tables in your database. Mhmm. Right? It just matches the schema. The column names match, etcetera. So Entity Framework actually doesn't depend on there being this direct relationship between them. Instead, it has this mapping layer. Part of that's determined just by defaults. It's called, convention over configuration.
So there's con some conventions, assumptions about how things will map. Mhmm. But then there's an entire library filled with possibilities to trans to change or or redefine those mappings. So we have a whole all these APIs to ex to describe, how we really want those objects to map to the schema in ways that will override those those defaults. Mhmm. So there's a lot of creativity in there, so you don't depend on that one to one relationship. So what's really nice about that is you're not you're not kind of not I don't wanna say forced to, but, you're not in a position where the way you have to design your applications Matt has to match the database. Yeah. Right? It can be you could design it the way that you need to design it to solve the problems you're solving, And then thanks to all the creative ways that the API lets you, describe how to go back and forth between the, schema of your objects and the schema of the database, lets you make, you know, make that flow through.
Yeah. So that's that's one of the big big differences, about entity framework. And then, you know, another really interesting advantage of that is that you don't have all of your developers writing their own ways of doing things or having to comply with, you know, remember the rules of how we're gonna do connections and commands and all of that. Like, Entity Framework has its way of doing that. Another thing that I haven't mentioned yet is that entity framework can't, when it comes to transforming into SQL or taking results and reading those results and and transforming them back, It really has to have a good understanding of the database itself, not just the schema, but how the database works. Yeah. So entity framework does the bulk of it, but then we have providers, some written by Microsoft, but many written by third parties, or even the owners of the providers.
So providers that have specific knowledge about kinda that last, transformation. Right? That last connection between entity framework any frameworks capabilities and the database. So, there's many, many, providers, and some some they're duplicates for. So for example, Microsoft has created a provider for SQL Server, surprise surprise. Mhmm. And, SQLite. And, and believe it or not, Cosmos DB, which isn't even a relational database.
[00:18:16] Unknown:
Yeah. But that, it it does work with, document databases as well. Right? Because, the problem that you were just talking about to translate tables with rows and columns into objects, that is one thing that it does. But then another problem that it solves is, to get rid of all the boilerplate code to Exactly. Exactly. To all the SQL and to connect to the database and to transform whatever data that is into objects. So Yeah. It does that also with Cosmos DB, for instance. Right?
[00:18:45] Unknown:
Exactly. So, you know, people are like, well, why would I do that? And the real answer to that is if you already have expertise with entity framework, it makes sense to say, well, why don't I just, you know, use that same logic and code that I already know how to do? So, for example, you know, I still wanna just be able to write a link query. So for those of you who might be not familiar with LINQ, LINQ is a query language within dot net, within the dotnet languages. Yep. So, you know, c sharp and and Visual Basic and f f sharp. So it's a really nice query language that lets you write queries, with your, you know, dot net objects.
And then it's actually used throughout dot net. Right? Like, that's the cool thing. There's a lot of you don't this isn't just for entity framework. It's just for in memory objects. However, Entity Framework has an extension of link that knows how to do what link knows how to do in terms of, translating those queries and then takes it to that next step, which is then translating it into SQL. So if we already know how to do all that and know how to execute the queries and know how to trigger the interaction with the database to happen with Entity Framework, there were so many people that said, can't you know, can't I just use Entity Framework to interact with Cosmos DB instead of having to learn a whole another, API or, you know, because there's dot net APIs and JavaScript APIs, etcetera, to do it. Yeah. I think that's also a good idea because it's like a standardized
[00:20:36] Unknown:
abstraction that most dot net developers know by now, the entity framework.
[00:20:41] Unknown:
But an important thing to understand is that document database is still very different from a relational database. So I don't think people should just blindly say, well, I've been using Entity Framework for years with SQL Server or SQLite, so I'm just gonna flip over to Cosmos DB. Right? You need to understand how Cosmos DB works. You need to understand how EF Core works with it. Right? Instead of just just using it. And and what would you do different than, for instance?
[00:21:11] Unknown:
Would you design the entities and the mappings differently?
[00:21:14] Unknown:
Well, the the mapping API is, a little different. But the other the other thing to be considerate of, and I I you know, look. I'm I'm not telling you because I'm sure you're very familiar with Cosmos DB, but, just, you know, thinking about what goes into a collection, what what you know, how you're gonna shape all of that Right. Information and how Entity Framework responds. So for example, if you have relationship, maybe, well, the ease the easy one that micros any framework teams use is a blog with posts. Right? The one to many relationship. If you have a one to many relationship like that, the the way that Entity Framework is going to persist it by default is it's gonna create a collection for blog, and it's gonna create a separate collection for posts.
Right. Right? Yep. They're not a document because posts have their own identity identity. However, if you use the feature of Entity Framework Core called owned entities, which lets you define essentially your a complex type that is used as a property of another entity. Right? So it doesn't have its own identity. It's like, you know, just it's it's just a it's another type, but it's it's not an entity. That, by default, will get stored as a a sub document. Right? Because it's a it's just a property, but it's a property with its own set of properties. So those kinds of things. And how how that works by default as understanding how it works by default, understanding what you can change, understand the impact of the default or the changes, especially, not just on performance, but on pricing.
Yeah. Right? Collection. So it that that's why I wanna make sure you know, whenever I do talk about the fact that, oh, yeah. You can use the Cosmos DB provider Yeah. That people are aware that, you know, they should not just start using it without understanding how Cosmos DB works, how the storage works, how the pricing works, and how Entity Framework interprets things. I love doing that, though. I love debugging. I love doing experiments and tests, and not just test to make sure my, you know, unit tests, etcetera, to make sure my logic works, but I love exploring to see what, you know, what does entity framework do when I do this? What does it do when I do that? Right? I love I love that kind of debugging. Yeah.
Just but that's how I learn it. Right? That's how I learn it. And then, you know, sometimes there's surprises.
[00:24:04] Unknown:
Okay. That is very, good to know that, to be mindful when you, for instance, use a different provider. I've also noticed this when I started using the Cosmos provider as well. The Entity Framework has been through a lot of versions. Like you said, there's this family of what's called the Entity Framework, and then the newer family is what's called Entity Framework Core. This is where it gets a bit complicated because now with dotnet5, we lost the core moniker, at least for dotnet. But then other things like asp.net is still called asp.netcore.
And then entity framework is also still called entity framework core. Right? Entity framework core 5 point o. Yeah.
[00:24:48] Unknown:
And and I think that was a really good decision. The reason is because there's such a disparity between the original entity framework and entity framework core, especially when it comes to things like the fact that EF Core is cross platform. Yeah. Right? EF Core is where all of the innovation is going into, etcetera. But there's still, you know, people who still, like I said before, still have entity framework 6 in their applications, and there's no compelling reason to just switch it to EF Core. Right? It's working. Those applications really aren't, doing much in terms of evolving.
They're just they are working, churning away, doing their Yeah. Doing their work. So I think it's really important to have a really clear delineation between the old entity framework and the new EF Core. And so I think it was a good idea that they they kept Core on it instead of dropping it when dot net did. Because with dot net, dropping dot net you know, dropping core, we we were still we can still differentiate because the old dot net is really dot net framework. Yeah. Yeah. Right? It has that. Right? Unfortunately, entity framework has framework in both of its names. Yeah.
Right? So, like, what were what would they they would have to literally call it in order to really match, they would just have to call it entity. I don't think that would work. No. That would work. Alright. It's funny. I hadn't thought of that before.
[00:26:37] Unknown:
So with, with dot net Framework 5.0, the Entity Framework Core Entity Framework Core 5.0 was also released with lots and lots of new features. Like, if you look at Holy smokes. Microsoft docs to their website, there's this article of what's new in Entity Framework core 5 point o, and that's a 41 minute read. That's that's crazy.
[00:26:59] Unknown:
Can you maybe highlight a couple of The team didn't have to write the team didn't have to write that all at once because Yeah. Yeah. The way they broke it the way they break it down is, they had 8 previews because they really, you know, just like dotnet does andasp.netcore does, they really engage the community in, you know, they do these preview releases, and, a lot of people will use it and hammer on it and give feedback. Yeah. So, so it you know, preview 1, 2, 3, 4, 5 through 8, and then release candidate, and then they released it. So, yeah, it's, they oh, I'm trying to think there this was before it was released early on, somebody from the team had blogged. Oh, it's Arthur Vickers who's, like, the lead on the team.
And he and this was still I think it was still in one of the previews, and he tweeted that there were there were already 637 GitHub issues closed. 299 bugs had been fixed. 225 feature new features and minor enhancements, and a 113 were docs, you know, cleaning up the docs. So, you know, interestingly, that was another really big push for them with EF Core 5, was making the docs better and better and better. Not just, showing syntax for things, but showing, you know, oh, if you're, using, Blazor. Right? This is a really good this here's an approach we would recommend, like, how you would, blend entity framework, weave entity framework into your application. Right? So guidance.
Yeah. That's why I don't need to write books anymore. The docs are kidding. The docs are so good. So that's that you know, they worked really, really hard on the technology, but then they, you know, turned around and really made the documentation an important focus as well. And and they're still working on that right now. But, yeah, that was that was, a really big deal. So a couple of the really interesting things that came to us in EF Core 5, and I'll just back up and explain that when they made the leap from e entity framework, the last version of entity framework is 6, although they've made some tweaks to it over the years, and now it's 6.4. Mhmm. But when they they went to EF Core, they rewrote it from scratch.
Right? They they're sayings, basically, you know, it's gonna work just about the same, but they were they felt that they were really stuck with this very old code base that had been basically created in, like, 2006. So they wanted to rewrite it from the ground up using modern software practices and also getting rid of a lot of the kind of code that was in there that was just locking them and blocking them from, evolving in directions that they wanted to go. Yeah. So because it was a, you know, a a replacement, there was no way they could get all the features that, you know, EF 6 had come a long way. Right? And and it was really evolved, and it was very feature rich. And there was no way they could get all the same features into EF Core as people were used to at EF 6. So they focused on, you know, the most used stuff, the most you know, that's that that's how they prioritized. Right? The the stuff that most people are using.
And then over time with EF Core, they're trying to they're bringing in more and more of those, features. Like, they're they refer to that as parity with with EF 6, to bring more and more of those features in. And, you know, there are some of these features that maybe not not a lot of people use, but to the people who use them, they're really important. Yeah. Yeah. Some of the ones that were missing features that had been driving some people just you know, they were just so frustrated. They're like, we still you know, we cannot use EF Core until it has these features. We can't switch over until it has these features.
But, again, you know, they weren't as critical to the bulk of people using it. One of them was many to many, supporting many to many relationships between, between entities, and that came back so we had a kind of a a, there was a way to do it starting with the f core, but it wasn't as simple. We didn't have what we refer to as the skip navigation. So that means, you know, if you've got, let's go back to blogs. So you might have a a blog that has multiple authors. Right? And then some of those authors might be writing in a variety of blogs.
Yeah. So the skip navigations would mean that in the blog object or the blog class, you just have a a property that's a list of authors. Right? A collection list of authors or collection of authors. And in the author class, you have a list of blogs that the author writes for. And the Entity Framework under the covers figures out that that is a many to many relationship. And in a relational database, you need to have a join table to track, you know, author number 1 writes for blog number 3. Author number 2 also writes for blog number 3. Author number 1 also writes happens to write for blog number 17. Right? So just that that join entity.
So the way that worked in old entity framework, that part was really nice. But if you wanted to do anything else a little more creative, hey. When did that author start writing for the blog? Then the whole thing breaks, and you had to actually, do set up the relationship manually. Entity Framework couldn't just magically figure it out under the covers. So they didn't want to just duplicate that. They really needed to think about it and also set Entity Framework up, do some things inside of entity framework to support a better way of having many to many so you weren't limited when you were using it. And they finally achieved that with some, some work that they did in entity framework core 3 that was maybe not visible to people using it, but it was, you know, kinda foundation stuff. And then they finally were able to do that with EF Core 5. And so EF Core 5, we have this really simple way of skip navigations just working, but there's also a lot of other very creative things you can do with it.
And what's happening under the covers isn't magic, right, that that you can't do anything with. It's there's a lot of really solid stuff, really fascinating stuff underneath the covers that's happening. So that was a a a really interesting and kind of a flagship feature that came into EF Core 5 that gave us more parity with e, entity framework. And, you know, there's there's some other things like that. But that reasoning of, you know, yes, we implemented it, you know, back in 2006, but the way it was implemented, we don't want to just duplicate that because there's a lot of problems with how that was written back then. Right? So there was a lot of things that they set up this foundation for, and then they were able to finally achieve it in EF Core 5. So so that's been really, really cool. Plus, it's just getting, you know, better and better and better. Right? As more people use it, they run into walls that prevent them from doing things the way they want to, and they, you know, the everything's very transparent, and the team responds to that, and they just, you know, make more and more improvements.
[00:35:42] Unknown:
Yeah. It just, it just keeps on going, which is great. Yeah. Which exactly.
[00:35:47] Unknown:
Instead of just throwing it out and starting all over again, say, oh, you know, we wanna do it differently. Like, they're really invested in it. Yeah.
[00:35:58] Unknown:
And, so there that's one. There are a lot more new feature. Is it something that you, also cover in one of your Pluralsight courses?
[00:36:08] Unknown:
Yeah. So, I have 2 courses about EF Core 5. 1 was actually a Webeter that I did that they published, and it's, I think, it's, like, an hour and a half long, and, it's called, I don't know, something like, moving from EF Core 3 to EF Core 5. It you know, it's it's what it could cover in in an hour or so. And it's really aimed at people who are using EF Core 3, so they understood about EF Core 5. One of, I think, you know, besides the many, many, many, many changes, one of the really important things to understand about moving from EF Core 3 to 5 is especially for those who moved from EF Core 2 to EF Core 3, EF Core 3 is what I refer to as the breaking changes edition. That was when they said, we're just focusing there weren't a lot of new features. They were focusing on really making the foundation really, really solid, and then they were able to do so much to, you know, to add on in EF Core 5 because of that.
So, peep it was such a big deal how much breaking changes there were. Very well documented, very well explained, each and every one. Anyway, a lot of people were worried that that was gonna happen again. Right? But, I mean, that was a sea change, right, to EF Core 3. So EF Core 5 does not have that slew of breaking changes. And then the other course that I have is, just a not just a. It's a getting started course. So, it's a great review for people who already use entity framework Core or Entity Framework to just get a feel for some of the stuff that's in EF Core 5, but it's also good for people who've never used entity framework at all before. Right? So for so the people who've used EF Core 3 maybe and are just kind of looking to see what's different, they might watch it a little more quickly and then go, oh, wait. Here's here's something that's a little different.
But it's not a a clear, you know, list of what's changed because it's really more aimed at, people who are just starting with entity framework. They've never used it before.
[00:38:32] Unknown:
Okay. That's great. I'll, link to those courses in, the show notes and also to, your blog when people can find you there as well.
[00:38:40] Unknown:
Awesome.
[00:38:41] Unknown:
Alright.
[00:38:42] Unknown:
Thank you very much for being on the show. Oh, Barry, it was a pleasure. Thanks for inviting me. Alright. And, you know, I always love to talk about entity framework.
[00:38:53] Unknown:
I know. Alright. Thank you very much. And this has been another episode of Developer Weekly. We'll talk to you next week. Could you please go to rate this podcast.com slash developerweekly and rate this podcast and leave a review? This helps me to spread the word about the podcast and helps other people to find it. That is rate this podcast.com/developerweekly. Thank you so much.