#databasemanagement — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #databasemanagement, aggregated by home.social.
-
Flyway the Right Way
A blog by RonaldSometimes when you upgrade your application the new version does not work correctly, and you need to downgrade. When you are unlucky you did some changes in your database that cannot be undone. In that case you need to restore the database from a backup, which is usually quite cumbersome and time-consuming. How nice would it be if you could just...
#dev #softwaredevelopment #SoftwareDevelopment #DatabaseManagement #Flyway #Rollback
-
Instant database clones with PostgreSQL 18
https://boringsql.com/posts/instant-database-clones/
#HackerNews #InstantDatabaseClones #PostgreSQL18 #DatabaseManagement #TechNews #BoringSQL
-
We Uncovered a Race Condition in Aurora RDS
https://hightouch.com/blog/uncovering-a-race-condition-in-aurora-rds
#HackerNews #RaceCondition #AuroraRDS #TechNews #CyberSecurity #CloudComputing #DatabaseManagement
-
Using the expand and contract pattern for schema changes
https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
#HackerNews #expandAndContract #schemaChanges #dataPatterns #databaseManagement #relationalDatabases #prisma
-
Using the expand and contract pattern for schema changes
https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
#HackerNews #expandAndContract #schemaChanges #dataPatterns #databaseManagement #relationalDatabases #prisma
-
Using the expand and contract pattern for schema changes
https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
#HackerNews #expandAndContract #schemaChanges #dataPatterns #databaseManagement #relationalDatabases #prisma
-
Using the expand and contract pattern for schema changes
https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
#HackerNews #expandAndContract #schemaChanges #dataPatterns #databaseManagement #relationalDatabases #prisma
-
Using the expand and contract pattern for schema changes
https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
#HackerNews #expandAndContract #schemaChanges #dataPatterns #databaseManagement #relationalDatabases #prisma
-
Ah, #CRDTs, because who doesn't love a good acronym party where you pretend your distributed to-do list is the next big thing? 🙄 Apparently, merging distributed databases is the new "big idea"—because copy-pasting in Google Docs wasn't groundbreaking enough. 🎉
https://lewiscampbell.tech/blog/250908.html #distributedDatabases #techHumor #innovation #databaseManagement #HackerNews #ngated -
phpMyAdmin is a free and open-source web-based database management tool written in PHP. With phpMyAdmin installed on Debian 12, system administrators and developers have a visual front end to aid in managing databases easily. Once set up and installed, it allows you to perform database management tasks on a running MySQL server via a web browser.
Keep reading:👇
https://greenwebpage.com/community/how-to-install-phpmyadmin-on-debian-12/#phpmyadmin #databasemanagement #php #mysql #debian #linuxadministration #greenwebpage
-
How to Run CRON Jobs in Postgres Without Extra Infrastructure
https://wasp.sh/blog/2025/05/28/how-to-run-cron-jobs-in-postgress-without-extra-infrastructure
#HackerNews #How #to #Run #CRON #Jobs #in #Postgres #Without #Extra #Infrastructure #Postgres #CRONJobs #DevOps #DatabaseManagement #TechTutorials
-
Declarative Schemas for simpler database management
https://supabase.com/blog/declarative-schemas
#HackerNews #DeclarativeSchemas #DatabaseManagement #SimplifiedTech #Supabase #HackerNews
-
🎉 🎩 Behold, the Postgres Language Server! Because who doesn't want their database management peppered with programmer mysticisms and AI-generated gibberish? 🤖🔍 Fear not, fellow developers, your SQL queries can now be mired in even more layers of abstraction and confusion! 🙃
https://github.com/supabase-community/postgres-language-server #PostgresLanguageServer #DatabaseManagement #SQLQueries #ProgrammerHumor #AIAbstraction #HackerNews #ngated -
🎉 Behold, the Holy Grail of Database Management: a single #PHP file! 🤯 Who needs stability, security, or readability when you can have this miraculous, spaghetti-coded, all-in-one monstrosity? 🍝💻 Remember, kids, because nothing says "reliable enterprise solution" like relying on a #GitHub repo to keep your database dreams alive. 🚀🤦♂️
https://github.com/vrana/adminer #DatabaseManagement #SpaghettiCode #EnterpriseSolutions #TechHumor #HackerNews #ngated -
How can I check the version and edition of SQL Server installed? http://dlvr.it/TJDRBX via PlanetPowerShell #SQLServer #DatabaseManagement #DataAnalysis #SQLQuery
-
How can I check the version and edition of SQL Server installed? http://dlvr.it/TJDRBX via PlanetPowerShell #SQLServer #DatabaseManagement #DataAnalysis #SQLQuery
-
How can I check the version and edition of SQL Server installed? http://dlvr.it/TJDRBX via PlanetPowerShell #SQLServer #DatabaseManagement #DataAnalysis #SQLQuery
-
How can I check the version and edition of SQL Server installed? http://dlvr.it/TJDRBX via PlanetPowerShell #SQLServer #DatabaseManagement #DataAnalysis #SQLQuery
-
How can I check the version and edition of SQL Server installed? http://dlvr.it/TJDRBX via PlanetPowerShell #SQLServer #DatabaseManagement #DataAnalysis #SQLQuery
-
Dawg who the hell put ice cream on my floppy???
#RetroComputing #VintageSoftware #dBaseII #DatabaseManagement #OldSchoolTech #FloppyDisk #SoftwareAutomation #TechHistory #Autocode
-
🧠 SQL Mindmap & Daily Life SQL Commands for Developers 🧠
SQL (Structured Query Language) is a powerful tool used by developers to manage and manipulate databases. Whether you're querying data, updating records, or performing complex joins, SQL is essential in daily development tasks. Let’s break it down!
#SQL #SQLCommands #DatabaseManagement #DevelopersLife #TechSkills #DatabaseDesign
-
Generic Repository Pattern in C#
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}I’m considering publishing the fully working example on Git with the following components.
- Services
- Domain
- Interfaces
- Repository
- Console App with basic CRUD operations
- Dependency Injection
Current Donation Amount
$2.41 – PayPal fees 🤑
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern 🚀✨
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
- Nicholas S 8.20.2024
#CodeEfficiency #CodeFirst #CRUDOperations #CSharp #DatabaseManagement #DbContext #DependencyInjection #DesignPatterns #EntityFramework #GenericRepository #Migrations #RepositoryPattern #SoftwareDevelopment #UnitofWork
-
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}I’m considering publishing the fully working example on Git with the following components.
- Services
- Domain
- Interfaces
- Repository
- Console App with basic CRUD operations
- Dependency Injection
Current Donation Amount
$2.41 – PayPal fees 🤑
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern 🚀✨
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
- Nicholas S 8.20.2024
https://vyechi.com/2024/08/20/generic-repository-pattern-in-c/
#CodeEfficiency #CodeFirst #CRUDOperations #CSharp #DatabaseManagement #DbContext #DependencyInjection #DesignPatterns #EntityFramework #GenericRepository #Migrations #RepositoryPattern #SoftwareDevelopment #UnitofWork
-
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}I’m considering publishing the fully working example on Git with the following components.
- Services
- Domain
- Interfaces
- Repository
- Console App with basic CRUD operations
- Dependency Injection
Current Donation Amount
$2.41 – PayPal fees 🤑
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern 🚀✨
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
- Nicholas S 8.20.2024
https://vyechi.com/2024/08/20/generic-repository-pattern-in-c/
#CodeEfficiency #CodeFirst #CRUDOperations #CSharp #DatabaseManagement #DbContext #DependencyInjection #DesignPatterns #EntityFramework #GenericRepository #Migrations #RepositoryPattern #SoftwareDevelopment #UnitofWork
-
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}I’m considering publishing the fully working example on Git with the following components.
- Services
- Domain
- Interfaces
- Repository
- Console App with basic CRUD operations
- Dependency Injection
Current Donation Amount
$2.41 – PayPal fees 🤑
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern 🚀✨
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
- Nicholas S 8.20.2024
https://vyechi.com/2024/08/20/generic-repository-pattern-in-c/
#CodeEfficiency #CodeFirst #CRUDOperations #CSharp #DatabaseManagement #DbContext #DependencyInjection #DesignPatterns #EntityFramework #GenericRepository #Migrations #RepositoryPattern #SoftwareDevelopment #UnitofWork
-
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}I’m considering publishing the fully working example on Git with the following components.
- Services
- Domain
- Interfaces
- Repository
- Console App with basic CRUD operations
- Dependency Injection
Current Donation Amount
$2.41 – PayPal fees 🤑
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern 🚀✨
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
- Nicholas S 8.20.2024
https://vyechi.com/2024/08/20/generic-repository-pattern-in-c/
#CodeEfficiency #CodeFirst #CRUDOperations #CSharp #DatabaseManagement #DbContext #DependencyInjection #DesignPatterns #EntityFramework #GenericRepository #Migrations #RepositoryPattern #SoftwareDevelopment #UnitofWork
-
Web-based database management tools like phpMyAdmin are widely used due to their ease of use and accessibility. However, there are significant security and performance reasons why you might want to avoid these tools in favor of desktop-based solutions like DBeaver.
https://linuxexpert.org/do-not-use-phpmyadmin/
#linux #windows #macos #DatabaseSecurity #DBeaver #phpMyAdmin #SecureConnections #SSH #VPN #DatabaseManagement #TechLesson #WebSecurity #RDBMS
-
Unlock your #Odoo potential! Learn #SoftwareTips for #PerformanceOptimization, managing environments, upgrading versions, and connecting #APITools. Enhance your #OdooDevelopment skills now! #ERP #BusinessSoftware #DatabaseManagement #TechGuide
https://teguhteja.id/enhancing-your-odoo-development-and-user-experience/
-
Enterprises increasingly turn to cloud and AI for database management https://www.helpnetsecurity.com/2024/06/27/ai-database-management-video/ #artificialintelligence #databasemanagement #cybersecurity #Don'tmiss #Hotstuff #Redgate #Video #cloud #video #News
-
PostgreSQL 16 Administration Cookbook now available on Amazon.com with a 25% discount! 📚✨ I will also be signing it at PGDay Chicago this Friday after my talk! Grab your copy now at https://packt.link/E7qyn 🛒
Come to PGDay Chicago: https://2024.pgdaychicago.org/
#PGDayChicago #PostgreSQL #Postgres #OpenSource #Database #DatabaseManagement #DatabaseAdministration #DBA #SQL
-
🔎Choosing between #MySQL & #MariaDB? No worries, #xTom has got you covered with top-notch infrastructure and services. Say hello to scalable database management! 👋🏼 #DatabaseManagement https://xt.om/Qtag
-
Real-time database platform SingleStore raises $80M more, now at a $940M valuation - Organizations are swimming in data these days, and so solutions to help manage and... - http://feedproxy.google.com/~r/Techcrunch/~3/Eio4bwr82SQ/ #hewlett-packardenterprise #cloudinfrastructure #googlecloudplatform #databasemanagement #paloaltonetworks #cloudcomputing #googleventures #khoslaventures #glynncapital #singlestore #vinodkhosla #enterprise #lonnejaffe #postgresql #computing #microsoft #database
-
The CockroachDB EC-1 - Every application is a palimpsest of technologies, each layer forming a base that ... - http://feedproxy.google.com/~r/Techcrunch/~3/ww1D9Vf15ss/ #eccloudandenterpriseinfrastructure #ecenterpriseapplications #databasemanagement #cockroachdbec-1 #cockroachlabs #cockroachdb #enterprise #databases #startups #database #mysql #ec-1 #saas
-
“Developers, as you know, do not like to pay for things” - In the previous part of this EC-1, we looked at the technical details of Cockroach... - http://feedproxy.google.com/~r/Techcrunch/~3/pecDJB46Ydw/ #eccloudandenterpriseinfrastructure #ecenterpriseapplications #distributedcomputing #cloudinfrastructure #databasemanagement #relationaldatabase #cockroachdbec-1 #cloudcomputing #cockroachlabs #cockroachdb #enterprise #databases #startups #oracle #cloud #mysql #ec-1 #saas #tc
-
Install phpMyAdmin With LEMP Stack On Ubuntu 20.04 LTS #phpmyadmin #nginx #mysql #php #lemp #DatabaseManagement #Linux #Ubuntu
https://www.ostechnix.com/install-phpmyadmin-with-lemp-stack-on-ubuntu-20-04-lts/ -
Install phpMyAdmin With LAMP Stack On Ubuntu 20.04 LTS #phpmyadmin #databasemanagement #apache #mysql #php #lamp #ubuntu #focalfossa #Linux
https://www.ostechnix.com/install-phpmyadmin-with-lamp-stack-on-ubuntu-20-04-lts/