RepoDb 1.0.0
Prefix ReservedSee the version list below for details.
dotnet add package RepoDb --version 1.0.0
NuGet\Install-Package RepoDb -Version 1.0.0
<PackageReference Include="RepoDb" Version="1.0.0" />
paket add RepoDb --version 1.0.0
#r "nuget: RepoDb, 1.0.0"
// Install RepoDb as a Cake Addin
#addin nuget:?package=RepoDb&version=1.0.0
// Install RepoDb as a Cake Tool
#tool nuget:?package=RepoDb&version=1.0.0
RepoDb by Michael Pendon A .Net class library used to create a dynamic entity repository-based data access to the database.
Whats with RepoDb?
- Supported Dynamic DbConnection
- Supported Mapping Command Type (Entity Level)
- Supported Execute Scalar
- Supported Primary Attribute (IsIdentity)
- Supported BaseRepository that uses the functionality of the DbRepository
- Supported the GetSqlStatement (Entity Level)
- Supported Object Driven approach when doing a query, delete, update and merge
- Supported Merge Method (Entity Level only)
- Supported Bulk Insert (SqlBulkCopy only)
- Supported to get the Connection at all Repositories
- Supported Transaction Handlers
- Supported Async methods
- Supported DbRepository property at the BaseRepository
- Supported Dynamic object returns for ExecuteReaderEx
- Supported code-guards at the DbRepository (Queryable, Insertable, Deletable, Mergeable, Updateable)
- Supported Type Mapper
How to use?
Below are some guidelines on how to use the RepoDb.
*** Creating an Entity
public interface IStock : IDataEntity { int Id { get; set; }
string ParentId { get; set; }
string Code { get; set; }
string Name { get; set; }
DateTime CreatedDate { get; set; }
DateTime ModifiedDate { get; set; }
}
[Map("[dbo].[Stock]")] public class Stock : DataEntity { [Ignore(Command.Insert | Command.Update)] [Primary] public int Id { get; set; }
public string ParentId { get; set; }
[Ignore(Command.Update)]
public string Code { get; set; }
public string Name { get; set; }
[Ignore(Command.Insert | Command.Update)]
public DateTime CreatedDate { get; set; }
[Ignore(Command.Insert)]
public DateTime ModifiedDate { get; set; }
}
- Map defines which object to use in the database. Usually defines the name of the table or a stored procedure
- Another param is the CommandType that tells whether the object is for TableDirect, StoredProcedure or Text base execution
- Ignore attribute is used in the property level to set a flag whether the property will be ignore on a certain commands (SELECT, DELETE, UPDATE, INSERT, MERGE)
- Primary attribute is used to flag a property as the primary field from the database object.
*** Creating a repository
public class StockRepository : BaseRepository<Stock, SqlConnection> { public StockRepository(ISettings settings) : base(settings.ConnectionString) { } }
- First dynamic type TEntity is a IDataEntity object that defines the entity to be used by the repository
- Second dynamic type TDbConnection is a type of Connection object to be used
- BaseRepository accepts 2 parameters in the constructor (ConnectionString and CommandTimeout)
*** Querying a data
var settings = new Settings(); var stockRepository = new StockRepository(settings.ConnectionString);
var stock = stockRepository.Query({ Id = 256 }); or var stock = stockRepository.Query(new List<IQueryField>() { new QueryField("Id", Operation.GreaterThanOrEqual, 50) });
- The first codes will return the Stock data from the database where the Id = 256;
- The second codes will return the Stock data from the database where the Id >= 50;
*** Updating a data
var settings = new Settings(); var stockRepository = new StockRepository(settings.ConnectionString); var stock = stockRepository.Query({ Id = 256 }); stock.Name = $"{stock.Name} - some updates";
var affectedRows = stockRepository.Update(stock); or var affectedRows = stockRepository.Update(stock, new { Id = 256 }); or var affectedRows = stockRepository.Update(stock, new List<IQueryField>() { new QueryField("Id", Operation.GreaterThanOrEqual, 50) });
*** Deleting a data
var settings = new Settings(); var stockRepository = new StockRepository(settings.ConnectionString); var stock = stockRepository.Query({ Id = 256 });
var affectedRows = stockRepository.Delete({ Id = 256 }); or var affectedRows = stockRepository.Delete(stock, new List<IQueryField>() { new QueryField("Id", Operation.GreaterThanOrEqual, 256) });
*** Merging a data
var settings = new Settings(); var stockRepository = new StockRepository(settings.ConnectionString); var stock = stockRepository.Query({ Id = 256 }); stock.Name = $"{stock.Name} - some merge updates";
var affectedRows = stockRepository.Merge(stock); or var affectedRows = stockRepository.Merge(stock, Field.From("ParentId", "Code"));
- Merge is only capable on a row level (for now)
- The 2nd parameter signifies the column to be used for qualifiers, if the parameter is not supplied, then the Primary field will be used
*** Bulk inserting a data
var settings = new Settings(); var stockRepository = new StockRepository(settings.ConnectionString); var stocks = new List<Stock>();
stocks.Add(new Stock() { .... }); . . . stocks.Add(new Stock() { .... });
var affectedRows = stockRepository.BulkInsert(stocks);
Above are the samples on how to use the basic CRUD operations.
RepoDb supports transactional operations and a direct execution of the DbCommand 3 popular methods (ExecuteNonQuery, ExecuteScalar, ExecuteReader)
var settings = new Settings();
var stockRepository = new StockRepository(settings.ConnectionString);
var stocks = stockRepository.CreateConnection().EnsureOpen().ExecuteNonQuery("SELECT * FROM [dbo].[Stock];"); // { ParentId = 23 });
You can even create a repository via DbRepository and access any entity that you like.
var settings = new Settings();
var repository = new DbRepository<SqlConnection>(settings.ConnectionString, settings.CommandTimeout);
var sale = repository.Query<Sale>({ TransactionDate = DateTime.Parse("2018-01-01 00:00:00.000") });
var stock = repository.Query<Stock>({ ParentId = sale.Id });
or
var sale = repository.CreateConnection().ExecuteReader<Sale>("SELECT * FROM [dbo].[Sale] WHERE (TransactionDate = @TD);", new { ID = DateTime.Parse("2018-01-01 00:00:00.000") });
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (17)
Showing the top 5 NuGet packages that depend on RepoDb:
Package | Downloads |
---|---|
RepoDb.SqlServer
A hybrid .NET ORM library for SQL Server. |
|
RepoDb.SqlServer.BulkOperations
An extension library that contains the official Bulk Operations of RepoDb for SQL Server. |
|
RepoDb.PostgreSql
A hybrid .NET ORM library for PostgreSQL. |
|
RepoDb.MySql
A hybrid .NET ORM library for MySQL (using MySql.Data). |
|
RepoDb.PostgreSql.BulkOperations
An extension library that contains the official Bulk Operations of RepoDb for PostgreSQL. |
GitHub repositories (6)
Showing the top 5 popular GitHub repositories that depend on RepoDb:
Repository | Stars |
---|---|
mikependon/RepoDB
A hybrid ORM library for .NET.
|
|
itlibrium/DDD-starter-dotnet
Sample implementation and comparison of various approaches to building DDD applications. Useful as a baseline to quickly start a DDD dot net project.
|
|
TortugaResearch/DotNet-ORM-Cookbook
This repository is meant to show how to perform common tasks using C# with variety of ORMs.
|
|
bcssov/IronyModManager
Mod Manager for Paradox Games. Official Discord: https://discord.gg/t9JmY8KFrV
|
|
FransBouma/RawDataAccessBencher
Bench code which tests entity materialization speed of various .NET data access / ORM implementations
|
Version | Downloads | Last updated |
---|---|---|
1.13.2-alpha1 | 667 | 2/26/2024 |
1.13.1 | 140,186 | 3/16/2023 |
1.13.0 | 71,292 | 11/2/2022 |
1.12.10 | 307,433 | 2/18/2022 |
1.12.9 | 30,715 | 9/27/2021 |
1.12.8 | 82,633 | 9/23/2021 |
1.12.7 | 169,627 | 2/6/2021 |
1.12.6 | 4,629 | 1/13/2021 |
1.12.5 | 9,698 | 12/30/2020 |
1.12.4 | 68,866 | 10/3/2020 |
1.12.3 | 3,103 | 9/29/2020 |
1.12.2 | 1,326 | 9/28/2020 |
1.12.1 | 1,387 | 9/25/2020 |
1.12.0 | 4,430 | 9/24/2020 |
1.3.2-alpha1 | 295 | 2/26/2024 |
- Initial Release for RepoDb (.Net Extension)
- Supported Dynamic DbConnection
- Supported Mapping Command Type (Entity Level)
- Supported Execute Scalar
- Supported Primary Attribute (IsIdentity)
- Supported BaseRepository that uses the functionality of the DbRepository
- Supported the GetSqlStatement (Entity Level)
- Supported Object Driven approach when doing a query, delete, update and merge
- Supported Merge Method (Entity Level only)
- Supported Bulk Insert (SqlBulkCopy only)
- Supported to get the Connection at all Repositories
- Supported Transaction Handlers
- Supported Async methods
- Supported DbRepository property at the BaseRepository
- Supported Dynamic object returns for ExecuteReaderEx
- Supported code-guards at the DbRepository (Queryable, Insertable, Deletable, Mergeable, Updateable)
- Supported Type Mapper