-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a16903
commit f827bbe
Showing
2 changed files
with
82 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Set the default behavior, in case people don't have core.autocrlf set. | ||
* text=lf | ||
|
||
# Explicitly declare text files you want to always be normalized and converted | ||
# to native line endings on checkout. | ||
*.cs text | ||
*.json text | ||
|
||
# Declare files that will always have CRLF line endings on checkout. | ||
*.sln text eol=crlf | ||
|
||
# Denote all files that are truly binary and should not be modified. | ||
*.png binary | ||
*.jpg binary |
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 |
---|---|---|
@@ -1,68 +1,68 @@ | ||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated> | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Gordon360.Models.CCT.Context | ||
{ | ||
public static class DbContextExtensions | ||
{ | ||
public static async Task<List<T>> SqlQueryAsync<T>(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class | ||
{ | ||
if (parameters is null) | ||
{ | ||
parameters = new object[] { }; | ||
} | ||
|
||
if (typeof(T).GetProperties().Any()) | ||
{ | ||
return await db.Set<T>().FromSqlRaw(sql, parameters).ToListAsync(cancellationToken); | ||
} | ||
else | ||
{ | ||
await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken); | ||
return default; | ||
} | ||
} | ||
|
||
public static async Task<int> GetNextValueForSequence(this DbContext _context, Sequence sequence) | ||
{ | ||
SqlParameter result = new SqlParameter("@result", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output }; | ||
await _context.Database.ExecuteSqlRawAsync($"SELECT @result = (NEXT VALUE FOR [{CCTSequenceEnum.GetDescription(sequence)}])", result); | ||
return (int)result.Value; | ||
} | ||
} | ||
|
||
public class OutputParameter<TValue> | ||
{ | ||
private bool _valueSet = false; | ||
|
||
public TValue _value; | ||
|
||
public TValue Value | ||
{ | ||
get | ||
{ | ||
if (!_valueSet) | ||
throw new InvalidOperationException("Value not set."); | ||
|
||
return _value; | ||
} | ||
} | ||
|
||
internal void SetValue(object value) | ||
{ | ||
_valueSet = true; | ||
|
||
_value = null == value || Convert.IsDBNull(value) ? default(TValue) : (TValue)value; | ||
} | ||
} | ||
} | ||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated> | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Gordon360.Models.CCT.Context | ||
{ | ||
public static class DbContextExtensions | ||
{ | ||
public static async Task<List<T>> SqlQueryAsync<T>(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class | ||
{ | ||
if (parameters is null) | ||
{ | ||
parameters = new object[] { }; | ||
} | ||
|
||
if (typeof(T).GetProperties().Any()) | ||
{ | ||
return await db.Set<T>().FromSqlRaw(sql, parameters).ToListAsync(cancellationToken); | ||
} | ||
else | ||
{ | ||
await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken); | ||
return default; | ||
} | ||
} | ||
|
||
public static async Task<int> GetNextValueForSequence(this DbContext _context, Sequence sequence) | ||
{ | ||
SqlParameter result = new SqlParameter("@result", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output }; | ||
await _context.Database.ExecuteSqlRawAsync($"SELECT @result = (NEXT VALUE FOR [{CCTSequenceEnum.GetDescription(sequence)}])", result); | ||
return (int)result.Value; | ||
} | ||
} | ||
|
||
public class OutputParameter<TValue> | ||
{ | ||
private bool _valueSet = false; | ||
|
||
public TValue _value; | ||
|
||
public TValue Value | ||
{ | ||
get | ||
{ | ||
if (!_valueSet) | ||
throw new InvalidOperationException("Value not set."); | ||
|
||
return _value; | ||
} | ||
} | ||
|
||
internal void SetValue(object value) | ||
{ | ||
_valueSet = true; | ||
|
||
_value = null == value || Convert.IsDBNull(value) ? default(TValue) : (TValue)value; | ||
} | ||
} | ||
} |