Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

DevQuestions with Tim Corey

DevQuestions with Tim Corey artwork

334. Is Entity Framework Still Relevant When AI Can Write SQL?

Nov 5, 202614 minAudio
ShareXLinkedInFacebookWhatsAppEmail

Entity Framework and other ORMs write the SQL for us. But are they necessary now that AI can do that work? Is the overhead of EF on every query worth the limited benefits we now get at design time? Do ORMs still make sense in light of AI-driven development? These are the questions we will answer in today's episode of DevQuestions. Website: https://www.DevForge.com/ Ask Your Question: https://suggestions.iamtimcorey.com/ Sign Up to Get More Great Developer Content in Your Inbox: https://signup.iamtimcorey.com/

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

SPEAKER_01Every technology, framework, and feature in software development has a drawback. That's the reason why we have so many options, and it's why it depends is such a common approach to any question. And software development is always changing. So we need to constantly evaluate what worked yesterday and see if it still works as well today. In this episode of Dev Questions, I want to start the conversation around ORMs and if they're even necessary anymore in light of AI-empowered development.

SPEAKER_00Welcome to the DevQuesti podcast with Tim Corey.

SPEAKER_01Software development is more than just writing code. So let's talk about the rest of it. Specifically, let's talk about if Entity Framework is still relevant to modern software development. Now, this episode is a bit different than normal. I want to talk through with you what I've been working through personally. I don't think this subject is decided yet, nor do I think there's one clear answer for everyone. However, I do think the landscape is shifting, and I want to use this as an opportunity to help you work through your own decision-making process around AI and development in general.

SPEAKER_01So let's start with a baseline understanding of entity framework. Now, it was designed to reduce TSQL by saying, hey, if you write a model in C sharp, just say that model is now on my table. And that reduces the TSQL you have to write. It makes database it makes database development faster at the expense a bit of the speed in production. Now, it accomplished this with a lot of generated code.

SPEAKER_01And it can be abused by developers who think they don't need to know SQL if they use Entity Framework. So I'm gonna be careful here. Entity framework is a great tool. It is also abused a lot. Okay, so there is a bit of a, you know, a little bit of column A, a little column B in any of these decisions. Now, if you want to boil it down to its essence, entity framework is supposed to make your development experience faster at the expense of runtime performance.

SPEAKER_01And again, to be clear, I'm not saying it makes your runtime performance terrible unless you abuse it. But it is gonna be a little bit slower than if you didn't use Entity Framework. It's got overhead. Now, as you probably know, personally, I like I like to use Dapper, which is a micro ORM. Okay. I still like to write the tSQL. Um I still have to do it myself. The I think the TSQL is pretty easy to write because I'm a SQL developer.

SPEAKER_01But also TSQL is easier to debug when it's in the database as opposed to ad hoc queries. Um I still have to maintain the database project. If you don't know, there is a database product type in Visual Studio or in.NET that you can then maintain your SQL project in and do things like refactoring, et cetera. But I still have to maintain that additional project as opposed to entity framework where that generated code does it for me. Now, every data call that I make, I have to write a query for, or at least have a query that will stand in for that.

SPEAKER_01I may have three or four calls that use the same query. To boil it down to its essence, Dapper makes my runtime performance faster at the expense of development performance, which is why I have always landed mostly on the side of using Dapper. I don't mind spending a bit of extra time in development to make my runtime performance faster. Now, now we have an understanding of these two options, I think it's time we ask some questions. Uh, number one, why is Entity Framework less performant?

SPEAKER_01And this comes down to assumptions. It's really what it comes down to. And so when you say, I have a model that has string first name, string last name, it doesn't know how big are those strings. Should they be 100 characters, 200 characters, 300 characters? We don't know. And so it does things like create Nvarchar Max fields for every string field, unless you specify a size, which makes sense when you think about it, because it doesn't know what size your string might be.

SPEAKER_01Those decisions, along with a number of others that can kind of pile on top of those, can cause overhead. They can cause your application to run slower, your database to run slower, queries to run slower. Now, yes, you can write better EF models where they say exactly how many characters and what data type it should be for a string type, et cetera. You can do a lot more work in C sharp to make sure that Entity Framework has all the information it needs so it doesn't have to make an assumption.

SPEAKER_01The problem is that it takes a lot of work. And that lot of work really reduces how much value you get out of entity framework, making your job easier. Okay. There's also just the overhead of it has to run a lot of code. There's a lot of code that has to run in order to build those queries, in order to send those queries across the wire, in order to get the data back. If you're not careful, then you can have a lot of duplicate, duplicate data come across the wire be so they can reconstitute that into a uh a nested model.

SPEAKER_01Now there's ways, again, to make that more efficient, but again, you have to know more about entity framework. But that's that's some of the reasons why entity framework is less performant. There's just the pure overhead of it's writing more code and also a lot of assumptions in your code that it has to make because it doesn't know unless you're really careful to specify everything. So why is Dapper development slower? Well, when you're writing a store procedure or a query by hand and then trying to keep those in sync every time you make a change, especially during the early development process, once you've kind of locked things in, it's a whole lot easier.

SPEAKER_01But when you're first developing, you're like, well, I think I'm gonna need first name, first name, and last name. So I'll create the table that has first name and last name, and then I'll create the store procedures for all the cred actions, you know, create, read, update, and delete. And then you go, hmm, I actually need first name, middle name, and last name. Okay. So I change a table, I change the the model, I change um every one of those store procedures. And now you go, okay, is that enough? And that's where the development process can be slower. So is there a way we can meet in the middle?

SPEAKER_01So you get, I want the development speed of entity framework with the production speed of Dapper. So the question is, can we get there? And I think the answer is yes, with AI assisted development. Now, some of you may have just cringed all over the place because I said AI in reference to your database, and you just got terrified. And there can be a good reason why you're terrified. Because, yeah, if if you are thinking about letting an AI loose in your database, don't do that.

SPEAKER_01That's scary, that's dangerous. But I'm not talking about that. I'm also not talking about telling the AI, just figure it out. Again, assumptions, not a good thing. But if you say, hey, I've built the database, AI, can you turn these tables into C sharp models? Super easy to do, low cost, you know, local models can do this very easily. So now all of a sudden, the the advantage of, well, I can do database first development with Entity Framework and have it create the models, I can do that with AI.

SPEAKER_01Only they're more efficient because of the fact that it's specific, no assumptions. Now, if you build them out the models in C sharp, an AI can turn your models into efficient SQL tables. And it can also create queries based upon what data you need. And if you change your model, an AI can update your tables and the associated views and store procedures if you even need that, because we also have a database project that can do refactoring, et cetera.

SPEAKER_01But with AI, we can do some of this boilerplate stuff. And this is where I think AI can really be a big benefit when it's assisting you, not leading, assisting you, because all of a sudden now you're allowing it to say, hey, here's your very strict requirements. Go do this thing. And you just need to check it. That's it. So you, in my opinion, user experience is an incredibly important part of a success of an application.

SPEAKER_01I've known organizations that have spent thousands of dollars per month in cloud resources just to throw resources at a poorly tuned entity framework system that they just couldn't tune anymore, it felt like. And they're just trying to get some type of performance out of it. And they're trying to overcome that poor performance that was baked into the code by just throwing more resources at it, more money. And that gives your users a bad experience because it's still slow and it crashes a lot or it's you know, it's taking a lot of resources, but it also increases the cost to your company.

SPEAKER_01By utilizing AI effectively, I think we can reduce the use of ORMs like Entity Framework, which allows us then to reduce costs and increase customer satisfaction. We can kind of have the best of both worlds. So this allows us to say, hey, I want some of that generation ability. But instead of trying to use code generators, which have to make broad assumptions from the factory essentially, um, Microsoft writes these code generators to work in the broadest number of circumstances.

SPEAKER_01Your AI assistant is building based upon your specific needs. And so it's very much more uh focused on you and less the generic, we hope this works for most people. And it's very specific to this should work for your specific case. So all of a sudden we have that same code generation, but instead of it being entity framework and boilerplate code and a lot of generated code that really we have to support, even though we didn't write it, and we might not even look at the code, which we've been doing that for years before AI.

SPEAKER_01Uh instead of doing that, we can actually use AI to help us use a faster tool like Dapr, or even just go ADO.net if you want. Although I think that Dapr provides enough tooling in that micro part without providing a whole lot of overhead. Um, I think it's worth it. But but even so, you can have this micro ORM that accesses our database very, very efficiently while at the same time not adding to our development experience. So while ORMs like Entity Framework are a big target, I don't think we should stop there.

SPEAKER_01Now, I would like you to think about how you can make um something better, more efficient in your software by using AI or using the new ways of doing things. So not just saying, hey, we've done this for years, that's the way we're gonna do it going forward, but thinking, hey, how can you be more efficient? How can you provide a better product for customers at a cheaper price, at a more, you know, a faster turnaround without creating AI slot, without creating unmaintainable code.

SPEAKER_01I'm not advocating for that. In fact, I'm advocating against that. But just because you can abuse something doesn't mean there isn't a place for it. Kind of like how entity framework can be abused, that's not to say there wasn't a place for it. But I think when we talk about AI and think about the new ways of doing software development, I think we need to think through how do you make this process better for everybody? So we want to create better software based upon wise decision making that does adjust with the times because the times are changing.

SPEAKER_01And if we just stay where we're at, we're gonna get left behind, like every generation before us that has done the same thing. So we need to think about adjusting. We need to think about, hey, where can we make things better and more efficient with these new ways of doing things without losing who we are, without making a poorer product, without making a messy product or a slop product, but instead making a more efficient product that's better for our users. All right. Thanks for listening. As always, I am Tim Corey.

SPEAKER_00Thank you for joining us for this episode of Dev Questions. When you're ready to learn to think and code like a professional developer, head over to imtimcorey.com and enroll in a course.

Open the transcript file

Hosts and Guests

Nobody is credited on this episode yet.

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. 333. Why Boring Technology Wins

    Oct 29, 202621 minAudio

    Why don't companies use the latest frameworks and systems? Why is .NET Framework still used in companies? Why don't companies follow industry best practices in their apps? Why can't I use the latest tech at my software...

    Credit the people on this episode

  2. 332. What To Do When You Are Burned Out

    Oct 22, 202628 minAudio

    What do I do if I am burned out? How do I get through burnout? How do I get to the other side? How do I endure my job and my situation while experiencing burnout? These are the questions we will answer in today's...

    Credit the people on this episode

  3. 331. .NET 8 and .NET 9 Both Expire Next Month: Is LTS Still a Thing?

    Oct 15, 202613 minAudio

    .NET 8 is the LTS version of .NET, but it expires next month. Why? Why does .NET 9 expire at the same time as .NET 8? How does LTS work with .NET and why is it so short? Do these versions stop working next month? Why...

    Credit the people on this episode

  4. 330. What To Do When Someone Pitches You An App Idea

    Oct 8, 202621 minAudio

    What do I do if my friend wants me to build an app? How do I evaluate if an app is a good idea? Who should own an app if one person has the idea and the other builds it? How do I say no to an app idea? These are the...

    Credit the people on this episode

  5. 329. Why Industry Specialization Can Unlock Job Opportunities for Developers

    Oct 1, 202611 minAudio

    Does having unrelated skills in a particular industry help in software development? If I switch careers, does my previous experience even count? Is my experience valuable to employers? These are the questions we will...

    Credit the people on this episode