https://github.com/roman-koshchei/unator
C# utilities, such as typesafe router. Breaking harmful standards is fine.
https://github.com/roman-koshchei/unator
breaking-standards csharp entity-framework-core utilities utils
Last synced: 11 months ago
JSON representation
C# utilities, such as typesafe router. Breaking harmful standards is fine.
- Host: GitHub
- URL: https://github.com/roman-koshchei/unator
- Owner: roman-koshchei
- License: mit
- Created: 2023-04-12T12:28:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T13:08:03.000Z (almost 2 years ago)
- Last Synced: 2025-02-09T20:26:27.514Z (over 1 year ago)
- Topics: breaking-standards, csharp, entity-framework-core, utilities, utils
- Language: C#
- Homepage: https://roman-koshchei.github.io/unator
- Size: 19.1 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# 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](#database--entity-framework-core)
2. [Environment variables](#environment-variables)
3. [Emails](#emails)
4. [Storage](#storage)
Check later: [github.com/BinaryBirds/swift-html](https://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
```csharp
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
```csharp
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`.