diff --git a/src/Core/RevEng.Core.60/Procedures/SqlServerStoredProcedureScaffolder.cs b/src/Core/RevEng.Core.60/Procedures/SqlServerStoredProcedureScaffolder.cs index 0b8e98fd7..b2af0276e 100644 --- a/src/Core/RevEng.Core.60/Procedures/SqlServerStoredProcedureScaffolder.cs +++ b/src/Core/RevEng.Core.60/Procedures/SqlServerStoredProcedureScaffolder.cs @@ -105,7 +105,9 @@ protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptio } Sb.AppendLine("}"); +#if !CORE80 GenerateOnModelCreating(model); +#endif } Sb.AppendLine("}"); @@ -191,7 +193,11 @@ protected override string WriteDbContextInterface(ModuleScaffolderOptions scaffo private static string GetDbContextExtensionsText(bool useAsyncCalls) { +#if CORE80 + var dbContextExtensionTemplateName = useAsyncCalls ? "RevEng.Core.DbContextExtensionsSqlQuery" : "RevEng.Core.DbContextExtensionsSqlQuery.Sync"; +#else var dbContextExtensionTemplateName = useAsyncCalls ? "RevEng.Core.DbContextExtensions" : "RevEng.Core.DbContextExtensions.Sync"; +#endif var assembly = typeof(SqlServerStoredProcedureScaffolder).GetTypeInfo().Assembly; using Stream stream = assembly.GetManifestResourceStream(dbContextExtensionTemplateName); if (stream == null) @@ -542,7 +548,7 @@ private void GenerateProcedure(Routine procedure, RoutineModel model, bool signa Sb.AppendLine("}"); } } - +#if !CORE80 private void GenerateOnModelCreating(RoutineModel model) { Sb.AppendLine(); @@ -577,7 +583,7 @@ private void GenerateOnModelCreating(RoutineModel model) Sb.AppendLine("}"); } - +#endif private void GenerateParameterVar(ModuleParameter parameter, Routine procedure) { Sb.Append($"var {ParameterPrefix}{parameter.Name} = "); diff --git a/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery b/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery new file mode 100644 index 000000000..8312db66d --- /dev/null +++ b/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery @@ -0,0 +1,61 @@ +// This file has been auto generated by EF Core Power Tools. +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace #NAMESPACE# +{ + public static class DbContextExtensions + { + public static async Task> SqlQueryAsync(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.Database + .SqlQueryRaw(sql, parameters) + .ToListAsync(cancellationToken); + } + else + { + await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken); + return default; + } + } + } + + public class OutputParameter + { + 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; + } + } +} diff --git a/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery.Sync b/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery.Sync new file mode 100644 index 000000000..847d81830 --- /dev/null +++ b/src/Core/RevEng.Core.80/DbContextExtensionsSqlQuery.Sync @@ -0,0 +1,61 @@ +// This file has been auto generated by EF Core Power Tools. +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace #NAMESPACE# +{ + public static class DbContextExtensions + { + public static List SqlQuery(this DbContext db, string sql, object[] parameters = null) where T : class + { + if (parameters is null) + { + parameters = new object[] { }; + } + + if (typeof(T).GetProperties().Any()) + { + return await db.Database + .SqlQueryRaw(sql, parameters) + .ToList(); + } + else + { + db.Database.ExecuteSqlRaw(sql, parameters); + return default; + } + } + } + + public class OutputParameter + { + 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; + } + } +} diff --git a/src/Core/RevEng.Core.80/RevEng.Core.80.csproj b/src/Core/RevEng.Core.80/RevEng.Core.80.csproj index 6546df44c..1ad6ad072 100644 --- a/src/Core/RevEng.Core.80/RevEng.Core.80.csproj +++ b/src/Core/RevEng.Core.80/RevEng.Core.80.csproj @@ -26,9 +26,9 @@ - - - + + + diff --git a/src/GUI/lib/efreveng80.exe.zip b/src/GUI/lib/efreveng80.exe.zip index 77a7a7e16..8f72397d9 100644 Binary files a/src/GUI/lib/efreveng80.exe.zip and b/src/GUI/lib/efreveng80.exe.zip differ