[
  {
    "path": ".gitattributes",
    "content": "###############################################################################\n# Set default behavior to automatically normalize line endings.\n###############################################################################\n* text=auto\n\n###############################################################################\n# Set default behavior for command prompt diff.\n#\n# This is need for earlier builds of msysgit that does not have it on by\n# default for csharp files.\n# Note: This is only used by command line\n###############################################################################\n#*.cs     diff=csharp\n\n###############################################################################\n# Set the merge driver for project and solution files\n#\n# Merging from the command prompt will add diff markers to the files if there\n# are conflicts (Merging from VS is not affected by the settings below, in VS\n# the diff markers are never inserted). Diff markers may cause the following \n# file extensions to fail to load in VS. An alternative would be to treat\n# these files as binary and thus will always conflict and require user\n# intervention with every merge. To do so, just uncomment the entries below\n###############################################################################\n#*.sln       merge=binary\n#*.csproj    merge=binary\n#*.vbproj    merge=binary\n#*.vcxproj   merge=binary\n#*.vcproj    merge=binary\n#*.dbproj    merge=binary\n#*.fsproj    merge=binary\n#*.lsproj    merge=binary\n#*.wixproj   merge=binary\n#*.modelproj merge=binary\n#*.sqlproj   merge=binary\n#*.wwaproj   merge=binary\n\n###############################################################################\n# behavior for image files\n#\n# image files are treated as binary by default.\n###############################################################################\n#*.jpg   binary\n#*.png   binary\n#*.gif   binary\n\n###############################################################################\n# diff behavior for common document formats\n# \n# Convert binary document formats to text before diffing them. This feature\n# is only available from the command line. Turn it on by uncommenting the \n# entries below.\n###############################################################################\n#*.doc   diff=astextplain\n#*.DOC   diff=astextplain\n#*.docx  diff=astextplain\n#*.DOCX  diff=astextplain\n#*.dot   diff=astextplain\n#*.DOT   diff=astextplain\n#*.pdf   diff=astextplain\n#*.PDF   diff=astextplain\n#*.rtf   diff=astextplain\n#*.RTF   diff=astextplain\n"
  },
  {
    "path": ".github/workflows/dotnet.yml",
    "content": "name: .NET\n\non:\n  push:\n    branches: [ master ]\n\njobs:\n  build:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v2\n    - name: Setup .NET\n      uses: actions/setup-dotnet@v1\n      with:\n        dotnet-version: 6.0.x\n    - name: Restore dependencies\n      run: dotnet restore EFCoreFluent\n    - name: Build\n      run: dotnet build EFCoreFluent --no-restore -c Release\n    - name: Publish Artifact\n      uses: actions/upload-artifact@v2.3.0\n      with:\n        name: Package\n        path: \"EFCoreFluent/src/EFCoreFluent/bin/Release/**.nupkg\"\n    \n    \n"
  },
  {
    "path": ".gitignore",
    "content": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n\n# User-specific files\n*.suo\n*.user\n*.userosscache\n*.sln.docstates\n\n# User-specific files (MonoDevelop/Xamarin Studio)\n*.userprefs\n\n# Build results\n[Dd]ebug/\n[Dd]ebugPublic/\n[Rr]elease/\n[Rr]eleases/\nx64/\nx86/\nbld/\n[Bb]in/\n[Oo]bj/\n[Ll]og/\n\n# Visual Studio 2015 cache/options directory\n.vs/\n# Uncomment if you have tasks that create the project's static files in wwwroot\n#wwwroot/\n\n# MSTest test Results\n[Tt]est[Rr]esult*/\n[Bb]uild[Ll]og.*\n\n# NUNIT\n*.VisualState.xml\nTestResult.xml\n\n# Build Results of an ATL Project\n[Dd]ebugPS/\n[Rr]eleasePS/\ndlldata.c\n\n# DNX\nproject.lock.json\nproject.fragment.lock.json\nartifacts/\n\n*_i.c\n*_p.c\n*_i.h\n*.ilk\n*.meta\n*.obj\n*.pch\n*.pdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.tmp_proj\n*.log\n*.vspscc\n*.vssscc\n.builds\n*.pidb\n*.svclog\n*.scc\n\n# Chutzpah Test files\n_Chutzpah*\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opendb\n*.opensdf\n*.sdf\n*.cachefile\n*.VC.db\n*.VC.VC.opendb\n\n# Visual Studio profiler\n*.psess\n*.vsp\n*.vspx\n*.sap\n\n# TFS 2012 Local Workspace\n$tf/\n\n# Guidance Automation Toolkit\n*.gpState\n\n# ReSharper is a .NET coding add-in\n_ReSharper*/\n*.[Rr]e[Ss]harper\n*.DotSettings.user\n\n# JustCode is a .NET coding add-in\n.JustCode\n\n# TeamCity is a build add-in\n_TeamCity*\n\n# DotCover is a Code Coverage Tool\n*.dotCover\n\n# NCrunch\n_NCrunch_*\n.*crunch*.local.xml\nnCrunchTemp_*\n\n# MightyMoose\n*.mm.*\nAutoTest.Net/\n\n# Web workbench (sass)\n.sass-cache/\n\n# Installshield output folder\n[Ee]xpress/\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish/\n\n# Publish Web Output\n*.[Pp]ublish.xml\n*.azurePubxml\n# TODO: Comment the next line if you want to checkin your web deploy settings\n# but database connection strings (with potential passwords) will be unencrypted\n#*.pubxml\n*.publishproj\n\n# Microsoft Azure Web App publish settings. Comment the next line if you want to\n# checkin your Azure Web App publish settings, but sensitive information contained\n# in these scripts will be unencrypted\nPublishScripts/\n\n# NuGet Packages\n*.nupkg\n# The packages folder can be ignored because of Package Restore\n**/packages/*\n# except build/, which is used as an MSBuild target.\n!**/packages/build/\n# Uncomment if necessary however generally it will be regenerated when needed\n#!**/packages/repositories.config\n# NuGet v3's project.json files produces more ignoreable files\n*.nuget.props\n*.nuget.targets\n\n# Microsoft Azure Build Output\ncsx/\n*.build.csdef\n\n# Microsoft Azure Emulator\necf/\nrcf/\n\n# Windows Store app package directories and files\nAppPackages/\nBundleArtifacts/\nPackage.StoreAssociation.xml\n_pkginfo.txt\n\n# Visual Studio cache files\n# files ending in .cache can be ignored\n*.[Cc]ache\n# but keep track of directories ending in .cache\n!*.[Cc]ache/\n\n# Others\nClientBin/\n~$*\n*~\n*.dbmdl\n*.dbproj.schemaview\n*.jfm\n*.pfx\n*.publishsettings\nnode_modules/\norleans.codegen.cs\n\n# Since there are multiple workflows, uncomment next line to ignore bower_components\n# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)\n#bower_components/\n\n# RIA/Silverlight projects\nGenerated_Code/\n\n# Backup & report files from converting an old project file\n# to a newer Visual Studio version. Backup files are not needed,\n# because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\nUpgradeLog*.htm\n\n# SQL Server files\n*.mdf\n*.ldf\n\n# Business Intelligence projects\n*.rdl.data\n*.bim.layout\n*.bim_*.settings\n\n# Microsoft Fakes\nFakesAssemblies/\n\n# GhostDoc plugin setting file\n*.GhostDoc.xml\n\n# Node.js Tools for Visual Studio\n.ntvs_analysis.dat\n\n# Visual Studio 6 build log\n*.plg\n\n# Visual Studio 6 workspace options file\n*.opt\n\n# Visual Studio LightSwitch build output\n**/*.HTMLClient/GeneratedArtifacts\n**/*.DesktopClient/GeneratedArtifacts\n**/*.DesktopClient/ModelManifest.xml\n**/*.Server/GeneratedArtifacts\n**/*.Server/ModelManifest.xml\n_Pvt_Extensions\n\n# Paket dependency manager\n.paket/paket.exe\npaket-files/\n\n# FAKE - F# Make\n.fake/\n\n# JetBrains Rider\n.idea/\n*.sln.iml\n\n# CodeRush\n.cr/\n\n# Python Tools for Visual Studio (PTVS)\n__pycache__/\n*.pyc"
  },
  {
    "path": "EFCoreFluent/EFCoreFluent.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 15\nVisualStudioVersion = 15.0.26403.7\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Snickler.EFCore\", \"src\\EFCoreFluent\\Snickler.EFCore.csproj\", \"{176191B5-C07B-4476-A213-416F122274BB}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|Any CPU = Debug|Any CPU\n\t\tRelease|Any CPU = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{176191B5-C07B-4476-A213-416F122274BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n\t\t{176191B5-C07B-4476-A213-416F122274BB}.Debug|Any CPU.Build.0 = Debug|Any CPU\n\t\t{176191B5-C07B-4476-A213-416F122274BB}.Release|Any CPU.ActiveCfg = Release|Any CPU\n\t\t{176191B5-C07B-4476-A213-416F122274BB}.Release|Any CPU.Build.0 = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityGlobals) = postSolution\n\t\tSolutionGuid = {D4190F00-F00E-4E37-8A65-A0B42B135CCA}\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "EFCoreFluent/src/EFCoreFluent/EFExtensions.cs",
    "content": "﻿using Microsoft.EntityFrameworkCore;\nusing System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations.Schema;\nusing System.Data;\nusing System.Data.Common;\nusing System.Linq;\nusing System.Reflection;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace Snickler.EFCore\n{\n    public static class EFExtensions\n    {\n        /// <summary>\n        /// Creates an initial DbCommand object based on a stored procedure name\n        /// </summary>\n        /// <param name=\"context\">target database context</param>\n        /// <param name=\"storedProcName\">target procedure name</param>\n        /// <param name=\"prependDefaultSchema\">Prepend the default schema name to <paramref name=\"storedProcName\"/> if explicitly defined in <paramref name=\"context\"/></param>\n        /// <param name=\"commandTimeout\">Command timeout in seconds. Default is 30.</param>\n        /// <returns></returns>\n        public static DbCommand LoadStoredProc(this DbContext context, string storedProcName,\n            bool prependDefaultSchema = true, short commandTimeout = 30)\n        {\n            var cmd = context.Database.GetDbConnection().CreateCommand();\n            cmd.CommandTimeout = commandTimeout;\n\n            if (prependDefaultSchema)\n            {\n                var schemaName = context.Model[\"DefaultSchema\"];\n                if (schemaName != null)\n                {\n                    storedProcName = $\"{schemaName}.{storedProcName}\";\n                }\n            }\n\n            cmd.CommandText = storedProcName;\n            cmd.CommandType = CommandType.StoredProcedure;\n\n            return cmd;\n        }\n\n        /// <summary>\n        /// Creates a DbParameter object and adds it to a DbCommand\n        /// </summary>\n        /// <param name=\"cmd\"></param>\n        /// <param name=\"paramName\"></param>\n        /// <param name=\"paramValue\"></param>\n        /// <param name=\"configureParam\"></param>\n        /// <returns></returns>\n        public static DbCommand WithSqlParam(this DbCommand cmd, string paramName, object paramValue,\n            Action<DbParameter> configureParam = null)\n        {\n            if (string.IsNullOrEmpty(cmd.CommandText) && cmd.CommandType != System.Data.CommandType.StoredProcedure)\n                throw new InvalidOperationException(\"Call LoadStoredProc before using this method\");\n\n            var param = cmd.CreateParameter();\n            param.ParameterName = paramName;\n            param.Value = paramValue ?? DBNull.Value;\n            configureParam?.Invoke(param);\n            cmd.Parameters.Add(param);\n            return cmd;\n        }\n\n        /// <summary>\n        /// Creates a DbParameter object and adds it to a DbCommand\n        /// </summary>\n        /// <param name=\"cmd\"></param>\n        /// <param name=\"paramName\"></param>\n        /// <param name=\"configureParam\"></param>\n        /// <returns></returns>\n        public static DbCommand WithSqlParam(this DbCommand cmd, string paramName,\n            Action<DbParameter> configureParam = null)\n        {\n            if (string.IsNullOrEmpty(cmd.CommandText) && cmd.CommandType != CommandType.StoredProcedure)\n                throw new InvalidOperationException(\"Call LoadStoredProc before using this method\");\n\n            var param = cmd.CreateParameter();\n            param.ParameterName = paramName;\n            configureParam?.Invoke(param);\n            cmd.Parameters.Add(param);\n            return cmd;\n        }\n\n        /// <summary>\n        /// Adds a SqlParameter to a DbCommand.\n        /// This enabled the ability to provide custom types for SQL-parameters.\n        /// </summary>\n        /// <param name=\"cmd\"></param>\n        /// <param name=\"parameter\"></param>\n        /// <returns></returns>\n        public static DbCommand WithSqlParam(this DbCommand cmd, IDbDataParameter parameter)\n        {\n            if (string.IsNullOrEmpty(cmd.CommandText) && cmd.CommandType != System.Data.CommandType.StoredProcedure)\n                throw new InvalidOperationException(\"Call LoadStoredProc before using this method\");\n\n            cmd.Parameters.Add(parameter);\n\n            return cmd;\n        }\n\n        /// <summary>\n        /// Adds an array of SqlParameters to a DbCommand\n        /// </summary>\n        /// <param name=\"cmd\"></param>\n        /// <param name=\"parameters\"></param>\n        /// <returns></returns>\n        /// <exception cref=\"InvalidOperationException\"></exception>\n        public static DbCommand WithSqlParams(this DbCommand cmd, IDbDataParameter[] parameters)\n        {\n            if (string.IsNullOrEmpty(cmd.CommandText) && cmd.CommandType != System.Data.CommandType.StoredProcedure)\n                throw new InvalidOperationException(\"Call LoadStoredProc before using this method\");\n\n            cmd.Parameters.AddRange(parameters);\n\n            return cmd;\n        }\n\n        public class SprocResults\n        {\n            private readonly DbDataReader _reader;\n\n            public SprocResults(DbDataReader reader)\n            {\n                _reader = reader;\n            }\n\n            public IList<T> ReadToList<T>() where T : new()\n            {\n                return MapToList<T>(_reader);\n            }\n\n            public T? ReadToValue<T>() where T : struct\n            {\n                return MapToValue<T>(_reader);\n            }\n\n            public Task<bool> NextResultAsync()\n            {\n                return _reader.NextResultAsync();\n            }\n\n            public Task<bool> NextResultAsync(CancellationToken ct)\n            {\n                return _reader.NextResultAsync(ct);\n            }\n\n            public bool NextResult()\n            {\n                return _reader.NextResult();\n            }\n\n            /// <summary>\n            /// Retrieves the column values from the stored procedure and maps them to <typeparamref name=\"T\"/>'s properties\n            /// </summary>\n            /// <typeparam name=\"T\"></typeparam>\n            /// <param name=\"dr\"></param>\n            /// <returns>IList&lt;<typeparam name=\"T\">&gt;</typeparam></returns>\n            private static IList<T> MapToList<T>(DbDataReader dr) where T : new()\n            {\n                var objList = new List<T>();\n                var props = typeof(T).GetRuntimeProperties().ToList();\n\n                var colMapping = dr.GetColumnSchema()\n                    .Where(x => props.Any(y =>\n                        string.Equals((y.GetCustomAttribute<ColumnAttribute>(true)?.Name ?? y.Name), x.ColumnName, StringComparison.CurrentCultureIgnoreCase)))\n                    .ToDictionary(key => key.ColumnName.ToUpper());\n\n                if (!dr.HasRows)\n                    return objList;\n\n                while (dr.Read())\n                {\n                    var obj = new T();\n                    foreach (var prop in props)\n                    {\n                        var upperName = (prop.GetCustomAttribute<ColumnAttribute>(true)?.Name ?? prop.Name).ToUpper();\n\n                        if (!colMapping.ContainsKey(upperName))\n                            continue;\n\n                        var column = colMapping[upperName];\n\n                        if (column?.ColumnOrdinal == null)\n                            continue;\n\n                        var val = dr.GetValue(column.ColumnOrdinal.Value);\n\n                        // Handle DateOnly and TimeOnly conversions, not supported by DBDataReader\n                        if (columnValue is DateTime dateTime)\n                        {\n                            Type propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;\n    \n                            if (propertyType == typeof(DateOnly))\n                            {\n                                columnValue = DateOnly.FromDateTime(dateTime);\n                            }\n                            else if (propertyType == typeof(TimeOnly))\n                            {\n                                columnValue = TimeOnly.FromDateTime(dateTime);\n                            }\n                        }\n                        \n                        prop.SetValue(obj, val == DBNull.Value ? null : val);\n                    }\n\n                    objList.Add(obj);\n                }\n\n                return objList;\n            }\n\n            /// <summary>\n            /// Attempts to read the first value of the first row of the result set.\n            /// </summary>\n            private static T? MapToValue<T>(DbDataReader dr) where T : struct\n            {\n                if (!dr.HasRows)\n                    return new T?();\n\n                if (dr.Read())\n                {\n                    return dr.IsDBNull(0) ? new T?() : dr.GetFieldValue<T>(0);\n                }\n\n                return new T?();\n            }\n        }\n\n        /// <summary>\n        /// Executes a DbDataReader and passes the results to <paramref name=\"handleResults\"/>\n        /// </summary>\n        /// <param name=\"command\"></param>\n        /// <param name=\"handleResults\"></param>\n        /// <param name=\"commandBehaviour\"></param>\n        /// <param name=\"manageConnection\"></param>\n        /// <returns></returns>\n        public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults> handleResults,\n            CommandBehavior commandBehaviour = CommandBehavior.Default,\n            bool manageConnection = true)\n        {\n            if (handleResults == null)\n            {\n                throw new ArgumentNullException(nameof(handleResults));\n            }\n\n            using (command)\n            {\n                if (manageConnection && command.Connection.State == ConnectionState.Closed)\n                    command.Connection.Open();\n                try\n                {\n                    using (var reader = command.ExecuteReader(commandBehaviour))\n                    {\n                        var sprocResults = new SprocResults(reader);\n                        handleResults(sprocResults);\n                    }\n                }\n                finally\n                {\n                    if (manageConnection)\n                    {\n                        command.Connection.Close();\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Executes a DbDataReader asynchronously and passes the results to <paramref name=\"handleResults\"/>\n        /// </summary>\n        /// <param name=\"command\"></param>\n        /// <param name=\"handleResults\"></param>\n        /// <param name=\"commandBehaviour\"></param>\n        /// <param name=\"ct\"></param>\n        /// <param name=\"manageConnection\"></param>\n        /// <returns></returns>\n        public static async Task ExecuteStoredProcAsync(this DbCommand command, Action<SprocResults> handleResults,\n            System.Data.CommandBehavior commandBehaviour = System.Data.CommandBehavior.Default,\n            CancellationToken ct = default, bool manageConnection = true)\n        {\n            if (handleResults == null)\n            {\n                throw new ArgumentNullException(nameof(handleResults));\n            }\n\n            using (command)\n            {\n                if (manageConnection && command.Connection.State == System.Data.ConnectionState.Closed)\n                    await command.Connection.OpenAsync(ct).ConfigureAwait(false);\n                try\n                {\n                    using (var reader = await command.ExecuteReaderAsync(commandBehaviour, ct)\n                        .ConfigureAwait(false))\n                    {\n                        var sprocResults = new SprocResults(reader);\n                        handleResults(sprocResults);\n                    }\n                }\n                finally\n                {\n                    if (manageConnection)\n                    {\n                        command.Connection.Close();\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Executes a DbDataReader asynchronously and passes the results thru all <paramref name=\"resultActions\"/>\n        /// </summary>\n        /// <param name=\"command\"></param>\n        /// <param name=\"commandBehaviour\"></param>\n        /// <param name=\"ct\"></param>\n        /// <param name=\"manageConnection\"></param>\n        /// <param name=\"resultActions\"></param>\n        /// <returns></returns>\n        public static async Task ExecuteStoredProcAsync(this DbCommand command,\n            CommandBehavior commandBehaviour = CommandBehavior.Default,\n            CancellationToken ct = default, bool manageConnection = true, params Action<SprocResults>[] resultActions)\n        {\n            if (resultActions == null)\n            {\n                throw new ArgumentNullException(nameof(resultActions));\n            }\n\n            using (command)\n            {\n                if (manageConnection && command.Connection.State == ConnectionState.Closed)\n                    await command.Connection.OpenAsync(ct).ConfigureAwait(false);\n                try\n                {\n                    using (var reader = await command.ExecuteReaderAsync(commandBehaviour, ct)\n                        .ConfigureAwait(false))\n                    {\n                        var sprocResults = new SprocResults(reader);\n\n                        foreach (var t in resultActions)\n                            t(sprocResults);\n                    }\n                }\n                finally\n                {\n                    if (manageConnection)\n                    {\n                        command.Connection.Close();\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Executes a non-query.\n        /// </summary>\n        /// <param name=\"command\"></param>\n        /// <param name=\"manageConnection\"></param>\n        /// <returns></returns>\n        public static int ExecuteStoredNonQuery(this DbCommand command, bool manageConnection = true)\n        {\n            var numberOfRecordsAffected = -1;\n\n            using (command)\n            {\n                if (command.Connection.State == ConnectionState.Closed)\n                {\n                    command.Connection.Open();\n                }\n\n                try\n                {\n                    numberOfRecordsAffected = command.ExecuteNonQuery();\n                }\n                finally\n                {\n                    if (manageConnection)\n                    {\n                        command.Connection.Close();\n                    }\n                }\n            }\n\n            return numberOfRecordsAffected;\n        }\n\n        /// <summary>\n        /// Executes a non-query asynchronously.\n        /// </summary>\n        /// <param name=\"command\"></param>\n        /// <param name=\"ct\"></param>\n        /// <param name=\"manageConnection\"></param>\n        /// <returns></returns>\n        public static async Task<int> ExecuteStoredNonQueryAsync(this DbCommand command, CancellationToken ct = default,\n            bool manageConnection = true)\n        {\n            var numberOfRecordsAffected = -1;\n\n            using (command)\n            {\n                if (command.Connection.State == ConnectionState.Closed)\n                {\n                    await command.Connection.OpenAsync(ct).ConfigureAwait(false);\n                }\n\n                try\n                {\n                    numberOfRecordsAffected = await command.ExecuteNonQueryAsync(ct).ConfigureAwait(false);\n                }\n                finally\n                {\n                    if (manageConnection)\n                    {\n                        command.Connection.Close();\n                    }\n                }\n            }\n\n            return numberOfRecordsAffected;\n        }\n    }\n}\n"
  },
  {
    "path": "EFCoreFluent/src/EFCoreFluent/Snickler.EFCore.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project Sdk=\"Microsoft.NET.Sdk\">\n\t<PropertyGroup>\n\t\t<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>\n\t\t<GeneratePackageOnBuild>true</GeneratePackageOnBuild>\n\t\t<AssemblyVersion>3.0.0.0</AssemblyVersion>\n\t\t<FileVersion>3.0.0.0</FileVersion>\n\t\t<PackageTags>snickler.efcore,entityframeworkcore,fluent,storedprocedure</PackageTags>\n\t\t<PackageProjectUrl>https://github.com/snickler/EFCore-FluentStoredProcedure</PackageProjectUrl>\n\t\t<PackageReadmeFile>README.md</PackageReadmeFile>\n\t\t<Copyright>\n\t\t</Copyright>\n\t\t<PackageLicenseUrl>https://github.com/snickler/EFCore-FluentStoredProcedure/blob/master/LICENSE</PackageLicenseUrl>\n\t\t<Authors>Jeremy Sinclair, contributors</Authors>\n\t\t<Version>3.0.0</Version>\n\t\t<Description>Fluent Stored Procedure Extensions for EntityFrameworkCore</Description>\n\t\t<PackageId>Snickler.EFCore</PackageId>\n\t\t<Product>Snickler.EFCore</Product>\n\t</PropertyGroup>\n\n\t<PropertyGroup>\n\t\t<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->\n\t\t<PublishRepositoryUrl>true</PublishRepositoryUrl>\n\n\t\t<!-- Embed source files that are not tracked by the source control manager in the PDB -->\n\t\t<EmbedUntrackedSources>true</EmbedUntrackedSources>\n\n\t\t<!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->\n\t\t<DebugType>embedded</DebugType>\n\t</PropertyGroup>\n\n\t<PropertyGroup Condition=\"'$(GITHUB_ACTIONS)' == 'true'\">\n\t\t<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>\n\t</PropertyGroup>\n\n\t<ItemGroup>\n\t\t<None Include=\"..\\..\\..\\README.md\" Pack=\"true\" PackagePath=\"\\\" />\n\t</ItemGroup>\n\n\t<ItemGroup>\n\t\t<PackageReference Include=\"Microsoft.SourceLink.GitHub\" Version=\"1.0.0\" PrivateAssets=\"All\" />\n\t</ItemGroup>\n\n\t<ItemGroup Condition=\" '$(TargetFramework)' == 'netstandard2.0'\">\n\t\t<PackageReference Include=\"Microsoft.EntityFrameworkCore.SqlServer\" Version=\"2.*\" />\n\t</ItemGroup>\n\t<ItemGroup Condition=\" '$(TargetFramework)' == 'net5.0'\">\n\t\t<PackageReference Include=\"Microsoft.EntityFrameworkCore.SqlServer\" Version=\"5.*\" />\n\t</ItemGroup>\n\t<ItemGroup Condition=\" '$(TargetFramework)' == 'net6.0'\">\n\t\t<PackageReference Include=\"Microsoft.EntityFrameworkCore.SqlServer\" Version=\"6.*\" />\n\t</ItemGroup>\n</Project>"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Jeremy Sinclair\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Snickler.EFCore\nFluent Methods for mapping Stored Procedure results to objects in EntityFrameworkCore\n\n\n\n[![NuGet](https://img.shields.io/nuget/v/Snickler.EFCore.svg)](https://www.nuget.org/packages/Snickler.EFCore)\n\n\n## Usage\n\n### Executing A Stored Procedure\n\nAdd the `using` statement to pull in the extension method. E.g: `using Snickler.EFCore`\n\n```csharp\n\n      var dbContext = GetDbContext();\n      dbContext.LoadStoredProc(\"dbo.SomeSproc\")\n               .WithSqlParam(\"fooId\", 1)              \n               .ExecuteStoredProc((handler) =>\n                {                  \n                    var fooResults = handler.ReadToList<FooDto>();      \n                    // do something with your results.\n                });\n\n```\n\n### Handling Multiple Result Sets\n\n```csharp\n\n      var dbContext = GetDbContext();\n      dbContext.LoadStoredProc(\"dbo.SomeSproc\")\n               .WithSqlParam(\"fooId\", 1)              \n               .ExecuteStoredProc((handler) =>\n                {                  \n                    var fooResults = handler.ReadToList<FooDto>();      \n                    handler.NextResult();\n                    var barResults = handler.ReadToList<BarDto>();\n                    handler.NextResult();\n                    var bazResults = handler.ReadToList<BazDto>()\n                });\n\n```\n\n### Handling Output Parameters\n\n```csharp\n\n      DbParameter outputParam = null;\n    \n      var dbContext = GetDbContext();\n      dbContext.LoadStoredProc(\"dbo.SomeSproc\")\n               .WithSqlParam(\"fooId\", 1)  \n               .WithSqlParam(\"myOutputParam\", (dbParam) =>\n               {                 \n                 dbParam.Direction = System.Data.ParameterDirection.Output;\n                 dbParam.DbType = System.Data.DbType.Int32;          \n                 outputParam = dbParam;\n               })\n               .ExecuteStoredProc((handler) =>\n                {                  \n                    var fooResults = handler.ReadToList<FooDto>();      \n                    handler.NextResult();\n                    var barResults = handler.ReadToList<BarDto>();\n                    handler.NextResult();\n                    var bazResults = handler.ReadToList<BazDto>()\n                });\n                \n                int outputParamValue = (int)outputParam?.Value;\n\n```\n\n### Using output parameters without returning a result set\n\n```csharp\n\n      DbParameter outputParam = null;\n\n      var dbContext = GetDbContext();\n\n      await dbContext.LoadStoredProc(\"dbo.SomeSproc\")\n            .WithSqlParam(\"InputParam1\", 1)\n            .WithSqlParam(\"myOutputParam\", (dbParam) =>\n            {\n                  dbParam.Direction = System.Data.ParameterDirection.Output;\n                  dbParam.DbType = System.Data.DbType.Int16;\n                  outputParam = dbParam;\n            })\n\n            .ExecuteStoredNonQueryAsync();\n\n      int outputParamValue = (short)outputParam.Value;\n\n```\n\n### Using output parameters without returning a result set but also getting the number of rows affected\n\nMake sure your stored procedure does not contain `SET NOCOUNT ON`.\n\n```csharp\n      int numberOfRowsAffected = -1;\n\n      DbParameter outputParam = null;\n\n      var dbContext = GetDbContext();\n\n      numberOfRowsAffected = await dbContext.LoadStoredProc(\"dbo.SomeSproc\")\n            .WithSqlParam(\"InputParam1\", 1)\n            .WithSqlParam(\"myOutputParam\", (dbParam) =>\n            {\n                  dbParam.Direction = System.Data.ParameterDirection.Output;\n                  dbParam.DbType = System.Data.DbType.Int16;\n                  outputParam = dbParam;\n            })\n\n            .ExecuteStoredNonQueryAsync();\n\n      int outputParamValue = (short)outputParam.Value;\n\n```\n\n### Changing the execution timeout when waiting for a stored procedure to return\n\n```csharp\n\n      DbParameter outputParam = null;\n\n      var dbContext = GetDbContext();\n\n      // change timeout from 30 seconds to 300 seconds (5 minutes)\n      await dbContext.LoadStoredProc(\"dbo.SomeSproc\", commandTimeout:300)\n            .WithSqlParam(\"InputParam1\", 1)\n            .WithSqlParam(\"myOutputParam\", (dbParam) =>\n            {\n                  dbParam.Direction = System.Data.ParameterDirection.Output;\n                  dbParam.DbType = System.Data.DbType.Int16;\n                  outputParam = dbParam;\n            })\n\n            .ExecuteStoredNonQueryAsync();\n\n      int outputParamValue = (short)outputParam.Value;\n\n```\n\n\n\n\n"
  }
]