![]() □ How to run PostgreSQL locally with Docker | Code4IT If you want to start working with PostgreSQL, a good way is to download it as a Docker image: But pay attention that not all the libraries are implemented by the EF team, some are third-party libraries (like the one we used for Postgres): In the link below you can find the full list. Using ( var db = new BoardGamesContext())Įntity Framework is impressive, and you can integrate it with tons of database vendors. So, the first thing to do is to define a class that inherits from DbContext: DB Contexts are the entry point to the tables, and the EF way to work with databases. The idea behind Entity Framework is to create DB Context objects that map database tables to C# data sets. Then, we need to define and configure the DB Context. The first thing to do is, as usual, install the related NuGet package. NET Core repository and the same database table we used when we performed CRUD operations with Dapper (a lightweight OR-M) and with NpgSql, which is the library that performs bare-metal operations. Let’s go! How to set up EF Coreįor this article, we will reuse the same. In this case, the best resource is its official documentation.īut the only way to learn it is by getting your hands dirty. There are a lot of things you should know about EF if you’re new to it. Then the result is automatically mapped to your C# classes.Įntity Framework supports tons of database engines, such as SQL Server, MySQL, Azure CosmosDB, Oracle, and, of course, PostgreSQL. ![]() ![]() With Entity Framework you don’t have to write SQL queries in plain text: you write C# code that gets automatically translated into SQL commands. In this article, we will perform CRUD operations with Entity Framework Core on a database table stored on PostgreSQL. Entity Framework (in short: EF) is an ORM built with in mind simplicity and readability. NET developers are lucky to have an incredibly powerful tool that can speed up their development: Entity Framework. When working with relational databases, you often come across two tasks: writing SQL queries and mapping the results to some DTO objects. We will use EF to integrate PostgreSQL in our application It seems that the old method to trigger a cascade delete is not anymore supported.With Entity Framework you can perform operations on relational databases without writing a single line of SQL. Move the PRAGMA command from the command query to the connection string.ĭata source=C:\Dbs\m圜ardDb.db foreign keys=true ![]() We were lucky with unit tests that cached this problem immediately after update. The cascade deletion was not triggered anymore by the above command. With the latest version of EF (6.1) in combination with SQLite NuGet Package (1.0.94) we had a big surprise. This was the expected behavior, taking into account that delete cascade feature was activated for that tables. WHERE (julianday(datetime('now'))-julianday(CarBuyDate))>360Įxecuted as a SQL command from Entity Framework used to trigger also the delete cascade in the tables around CarsHistory. Odd behavior of SQLite and Entity Framework It seems that in the new version of EF or SQLite the behavior or functionality of a specific feature was changed. And surprise, some of them are red, even if the application seems to run without any kind of problem. Now was the moment of true, to check if the unit tests are still green. After a few hours of working we manage to update SQLite and EF to the new version and we manage to make the application to compile and start. This days we had to update an application with the latest and greatest version of Entity Framework and SQLite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |