![]() You can find the code for this example on GitHub at UWP-MVVM-EF-SQLite-2. This week, I’ll show how to save the text box content in a database so it persists between app runs. However, when you close and re-open the app, the text is gone from both places. Last week’s example demonstrated XAML binding: type something in a text box, and when the text box loses focus, the text you typed appears in a text block below it. Nevertheless, I’ll mention a few things about what’s going on behind the scenes. Using Entity Framework commands, it’s possible to write code without knowing about the details of the physical database. When the app closes, the database does as well. When the app starts up, so does the database. Instead, everything runs in the app process. Unlike traditional databases, SQLite doesn’t use a server process that accepts connections from an app. SQLite is a popular choice, and is well-supported for UWP apps. For this example, I’m going to use a database stored on my local hard drive. To keep data around when the app closes or the computer restarts, we need some kind of data storage mechanism. : This provides Package Manager Console tools for EF Core, like the Add-Migration command that I’ll describe below.: This is an EF Core database provider, which is required to use EF Core with a specific database, in this case SQLite.It provides the DbContext and DbSet types that are used in this week’s example. Microsoft.EntityFrameworkCore: This is the main package for EF Core.Starting with my project from last week, I added the following packages: Also, a copy-and-pastable Install-Package command is provided on if you search for packages there. But once you know the package name, the command-line way can be faster. The GUI way makes it easier to search for the package you’re looking for inside Visual Studio. The command-line way: Open the Package Manager Console (under Tools - NuGet Package Manager), and use the Install-Package command.The GUI way: Right-click on the References folder and click Manage NuGet Packages.When you have a solution loaded in VS2015, there are two ways to add a NuGet package: NET world, the standard package manager is NuGet, which comes installed by default with Visual Studio 2015.NET Core uses NuGet to update itself, and other components like EF Core are also available through NuGet. Rather than keep track of that dependency graph manually, you can use a package manager. Furthermore, each of those components will depend on other components, and so on. Unless you’re building your whole project from the ground up, you’ll have a collection of other software components to manage. One of the challenges in a modern software project is keeping track of dependencies. NET Framework, but it doesn’t replace every piece of it. Another similarity: just as EF Core is similar but not identical to EF. NET Core was also released last year under an open-source license. UWP apps are built using a framework called. Although it doesn’t contain every feature of previous EF versions, I don’t expect to miss anything. ![]() ![]() That’s the version I’ll be using for my project. Microsoft has been shipping versions of Entity Framework since 2008, but last year they released an open-source version called Entity Framework Core. ORMs are not perfect, but for the app I’m building, the advantages outweigh the downsides. EF allows the developer to maintain a single mental model for how an app’s data is organized, rather than switching between an object model and a relational model. Its purpose is to keep all of the data access code for an app in one place, written in one language (C# in this case), and organized according to one design philosophy (object-oriented design). This week, I’m going to explore the data layer technologies that I’ll be using: Entity Framework and SQLite.Īs I mentioned in UWP, C#, XAML, MVVM, EF, and SQLite, Entity Framework is an object-relational mapping (ORM) framework. Last week, I covered some details about Model-View-ViewModel, a pattern that helps simplify user interface code and make it more testable. This year, I’m building a UWP time tracking app. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |