roman-koshchei / unator

C# utilities, such as typesafe router. Breaking harmful standards is fine.

Home Page:https://roman-koshchei.github.io/unator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unator banner

Unator

Breaking mistaken standards of enterprise such as Repository pattern. My goal is to provide a set of functions/classes to make development transparent and logical.

  1. Database
  2. Environment variables
  3. Emails
  4. Storage

Check later: github.com/BinaryBirds/swift-html

Database / Entity Framework Core

Probably you use Entity Framework Core to access database. I do so. But you may be taught to use Repository pattern and throw exceptions. Not anymore! I see too few benefits to add complexity of Repository.

So we will use just few generic extensions for database. And our code will look like this:

Querying data

var products = await db.Products
  .Where(x => x.Price < 100)
  .Select(x => new { x.Id, x.Title })
  .QueryMany();

var product = await db.Products
  .Select(x => new { x.Id, x.Title })
  .QueryOne(x => x.Id == 51);

QueryMany and QueryOne allow to get data. You can pass where condition right into function or do it before. Both functions are configured with ConfigureAwait(false). When you query one entity it returns null if entity isn't found.

The benefit is you remove complexity and query minimal amount of data by using Select.

Modifying data

var product = new Product("Title for new product");
await db.Products.AddAsync(product)
var saved = await db.Save();

Save for DbContext allow us to save changes to the database without throwing exceptions. It just returns true if changes saved successfully otherwise false.

About

C# utilities, such as typesafe router. Breaking harmful standards is fine.

https://roman-koshchei.github.io/unator

License:MIT License


Languages

Language:C# 90.9%Language:HTML 6.7%Language:Dockerfile 2.5%