-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added EntityFrameworkCore. * Fixed docs.
- Loading branch information
Showing
15 changed files
with
486 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## LightResults.Extensions.EntityFrameworkCore | ||
|
||
Provides a DbContext that wraps context operations using LightResults. | ||
|
||
### New method definitions | ||
|
||
The following methods are wrapped internally with a `try { } catch { }` block and have their signatures | ||
updated to result a `Result`. If an exception occurs, a failed result will be returned and the `Exception` | ||
will be added to the result as metadata. | ||
|
||
- `AddAsync()` | ||
- `AddAsync<TEntity>()` | ||
- `AddRangeAsync()` | ||
- `Find()` | ||
- `Find<TEntity>()` | ||
- `FindAsync()` | ||
- `FindAsync<TEntity>()` | ||
- `SaveChanges()` | ||
- `SaveChangesAsync()` | ||
|
||
#### Getting the `Exception` | ||
|
||
```csharp | ||
var result = dbContext.SaveChangesAsync(); | ||
if (result.IsFailed) | ||
{ | ||
var ex = (Exception)result.Error.Metadata["Exception"]; | ||
// Do something with the base exception type or... | ||
if (ex is DbUpdateException dbUpdateException) | ||
{ | ||
// Do something with a specific exception type | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## LightResults.Extensions.ExceptionHandling | ||
|
||
Provides extension methods for exception handling using LightResults. | ||
|
||
### Try method | ||
|
||
The `Try` method will wrap the execution of an `Action` or `Func` in a `try { } catch { }` block. If an | ||
exception occurs, a failed result will be returned and the `Exception` will be added to the result as metadata. | ||
|
||
#### With an `Action` | ||
|
||
```csharp | ||
var result = action.Try(); | ||
if (result.IsSuccess) | ||
{ | ||
// Do something | ||
} | ||
``` | ||
|
||
#### With an `Action` with arguments | ||
|
||
```csharp | ||
var result = action.Try(42); | ||
if (result.IsSuccess) | ||
{ | ||
// Do something | ||
} | ||
``` | ||
|
||
#### With a `Func` | ||
|
||
```csharp | ||
var result = func.Try(); | ||
if (result.IsSuccess) | ||
{ | ||
var value = result.Value; | ||
// Do something | ||
} | ||
``` | ||
|
||
#### With a `Func` with arguments | ||
|
||
```csharp | ||
var result = func.Try(42); | ||
if (result.IsSuccess) | ||
{ | ||
var value = result.Value; | ||
// Do something | ||
} | ||
``` | ||
|
||
#### Getting the `Exception` | ||
|
||
```csharp | ||
var result = action.Try(); | ||
if (result.IsFailed) | ||
{ | ||
var ex = (Exception)result.Error.Metadata["Exception"]; | ||
// Do something with the base exception type or... | ||
if (ex is ArgumentNullException argumentNullException) | ||
{ | ||
// Do something with a specific exception type | ||
} | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.