A hybrid ORM library for .NET.
$ dotnet add package AmpScm.RepoDbRepoDB is an open-source .NET ORM library that bridges the gaps of micro-ORMs and full-ORMs. It helps you simplify the switch-over of when to use the BASIC and ADVANCE operations during the development.
At the Package Manager Console, write the command below.
Install-Package AmpScm.RepoDb
Or, visit our installation page for more information.
After the installation, any library operation can then be called. Please see below for the samples.
using (var connection = new SqlConnection(ConnectionString))
{
var customer = connection.ExecuteQuery<Customer>("SELECT * FROM [dbo].[Customer] WHERE (Id = @Id);", new { Id = 10045 }).FirstOrDefault();
}var customer = new
{
FirstName = "John",
LastName = "Doe",
IsActive = true
};
using (var connection = new SqlConnection(ConnectionString))
{
var id = connection.ExecuteScalar<int>("INSERT INTO [dbo].[Customer](FirstName, LastName, IsActive) VALUES (@FirstName, @LastName, @IsActive); SELECT SCOPE_IDENTITY();", customer);
}using (var connection = new SqlConnection(ConnectionString))
{
var customer = new
{
Id = 10045,
FirstName = "John",
LastName = "Doe"
};
var affectedRows = connection.ExecuteNonQuery("UPDATE [dbo].[Customer] SET FirstName = @FirstName, LastName = @LastName, LastUpdatedUtc = GETUTCDATE() WHERE (Id = @Id);", customer);
}using (var connection = new SqlConnection(ConnectionString))
{
var deletedRows = connection.ExecuteNonQuery("DELETE FROM [dbo].[Customer] WHERE (Id = @Id)", new { Id = 10045 });
}using (var connection = new SqlConnection(ConnectionString))
{
var customer = connection.ExecuteQuery<Customer>("[dbo].[sp_GetCustomer]", new { Id = 10045 }, commandType: CommandType.StoredProcdure).FirstOrDefault();
}Or via direct calls.
using (var connection = new SqlConnection(ConnectionString))
{
var customer = connection.ExecuteQuery<Customer>("EXEC [dbo].[sp_GetCustomer](@Id);", new { Id = 10045 }).FirstOrDefault();
}Or, visit the official get-started page for SQL Server.