@manhng

Welcome to my blog!

CQRS Raw SQL and DDD with Dapper

January 5, 2022 16:47

CQRS Raw SQL and DDD with Dapper (edit)

  • MyProject.Api
  • MyProject.Application
  • MyProject.Infrastructure
  • MyProject.Domain

Simple CQRS implementation with raw SQL and DDD

Simple CQRS implementation with raw SQL and DDD - Kamil Grzybek

Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture

kgrzybek/sample-dotnet-core-cqrs-api: Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture. (github.com)

  • DDD
  • Clean Architecture
  • Unit Testing
  • Integration Testing
  • Dapper
  • Sql Server
  • Serilog
  • Microsoft.NET.Test.Sdk
  • NUnit3T
  • NSubstitut

sample-dotnet-core-cqrs-api/SampleProject.IntegrationTests.csproj at master · gtechsltn/sample-dotnet-core-cqrs-api (github.com)

ASP.NET Core Web API: Plugin Controllers and Services

The middle ground between monolithic applications and an explosion of microservices
This is a concise guide on how to implement plugin controllers and share services between the ASP.NET Web API application and the plugin.

ASP.NET Core Web API: Plugin Controllers and Services - CodeProject

Executing Raw SQL Queries using Entity Framework Core

February 12, 2020 23:51

The way to executing raw SQL in EF Core (edit)

EF Core Extension class

    public static class EFCoreExt
    {
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public static List<TExecuteQuery<T>(this DBContext dbstring querywhere T : classnew()
        {
            using (var command = db.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = query;
                command.CommandType = CommandType.Text;
 
                db.Database.OpenConnection();
 
                using (var reader = command.ExecuteReader())
                {
                    var lst = new List<T>();
                    var lstColumns = new T().GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToList();
                    while (reader.Read())
                    {
                        var newObject = new T();
                        for (var i = 0; i < reader.FieldCount; i++)
                        {
                            var name = reader.GetName(i);
                            PropertyInfo prop = lstColumns.FirstOrDefault(a => a.Name.ToLower().Equals(name.ToLower()));
                            if (prop == null)
                            {
                                continue;
                            }
                            var val = reader.IsDBNull(i) ? null : reader[i];
                            prop.SetValue(newObjectvalnull);
                        }
                        lst.Add(newObject);
                    }
 
                    return lst;
                }
            }
        }

Categories

Recent posts