PPM.MicroORM

Custom implementation of Micro-ORM including

Query, QueryAsync, QueryFirstOrDefault, QueryFirstOrDefaultAsync, QueryFirst, QueryFirstAsync, Single, SingleAsync, SingleOrDefault, SingleOrDefaultAsync, Execute and ExecuteAsync.

Getting Started

* This example will describe about asynchronous methods. All LINQ methods support both synchronous and asynchronous.

1. Install the NuGet Package

dotnet add package PPM.MicroORM

2. Install Other Dependencies


<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        

3. Read Action Examples

QueryAsync


string query = BlogQuery.BlogListQuery;
var parameters = new List<SqlParameter>()
{
    new("@IsDeleted", false)
};

using var db = new SqlConnection(_connectionString);
var lst = await db.QueryAsync<BlogModel>(query, parameters);
        

QueryFirstOrDefaultAsync


string query = BlogQuery.GetBlogByIdQuery;
var parameters = new List<SqlParameter>()
{
    new SqlParameter("@BlogId", id),
    new SqlParameter("@IsDeleted", false)
};

using var db = new SqlConnection(_connectionString);
var item = await db.QueryFirstOrDefaultAsync<BlogModel>(query, parameters);
        

QueryFirstAsync

  • It is an asynchronous method.
  • It returns only one element even when the sequence contains more than one element.
  • Throws an error when there is no matching record.
  • SingleAsync

  • It is an asynchronous method.
  • Ensures that there is only one record
  • Throws error if there is no element in the sequence.
  • Throws error if there is more than one element.
  • SingleOrDefaultAsync

  • It is an asynchronous method.
  • Returns null if there is no element in the sequence.
  • Throws error if there is more than one element in the sequence.
  • 4. Write Actions

    
    string query = BlogQuery.AddBlogQuery;
    
    var parameters = new List()
    {
        new SqlParameter("@BlogTitle", blogTitle),
        new SqlParameter("@BlogAuthor", blogAuthor),
        new SqlParameter("@BlogContent", blogContent)
    };
    
    using var db = new SqlConnection(_connectionString);
    int result = await db.ExecuteAsync(query, parameters);