<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sudip</title>
    <description>The latest articles on Forem by Sudip (@hisudip_).</description>
    <link>https://forem.com/hisudip_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1102733%2F48770d97-7cd9-4a78-8924-b730f3a162a1.jpg</url>
      <title>Forem: Sudip</title>
      <link>https://forem.com/hisudip_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hisudip_"/>
    <language>en</language>
    <item>
      <title>Fetching dynamic columns using StoredProcedure in EntityFramework</title>
      <dc:creator>Sudip</dc:creator>
      <pubDate>Fri, 16 Jun 2023 15:00:09 +0000</pubDate>
      <link>https://forem.com/hisudip_/fetching-dynamic-columns-using-storedprocedure-in-entityframework-1o94</link>
      <guid>https://forem.com/hisudip_/fetching-dynamic-columns-using-storedprocedure-in-entityframework-1o94</guid>
      <description>&lt;p&gt;Sometimes, you have to return dynamic columns with names e.g. column-1, column-2, …, column-n from the stored procedure. Since the column is varying in terms of name and number, it is difficult to map to our Model class.&lt;/p&gt;

&lt;h2&gt;
  
  
  What would be the solution?
&lt;/h2&gt;

&lt;p&gt;One of the solutions is returning IDictionary. The code is given below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public async Task&amp;lt;IEnumerable&amp;lt;IDictionary&amp;lt;string, object&amp;gt;&amp;gt;&amp;gt; GetDynamicDataFromSPAsync(string storedProcedureName, string connectionString, object[]? parameter = null)
    {
        List&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt; items = new List&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt;();

        if (connectionString is null)
        {
            return items;
        }
        using (var connection = new SqlConnection(connectionString))
        {
            await connection.OpenAsync();
            using (var command = new SqlCommand(storedProcedureName, connection))
            {
                if (parameter is not null)
                {
                    command.Parameters.AddRange(parameter);
                }
                command.CommandType = CommandType.StoredProcedure;
                using (var reader = await command.ExecuteReaderAsync())
                {
                    if (reader.HasRows)
                    {
                        while (await reader.ReadAsync())
                        {
                            Dictionary&amp;lt;string, object&amp;gt; obj = new Dictionary&amp;lt;string, object&amp;gt;();

                            for (int i = 0; i &amp;lt; reader.FieldCount; i++)
                            {
                                string columnName = reader.GetName(i);
                                object columnValue = reader.GetValue(i);
                                obj[columnName] = columnValue;
                            }
                            items.Add(obj);
                        }
                    }
                }
            }
        }
        return items;

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can write the &lt;strong&gt;object[] parameter&lt;/strong&gt; as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var parameter= new object[]
            {
             new SqlParameter("@PersonId", SqlDbType.Int) { Value = 1},                  
             new SqlParameter("@CountryCode", SqlDbType.VarChar) { Value = "AU"}
            };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Response Compression in a .Net Core API</title>
      <dc:creator>Sudip</dc:creator>
      <pubDate>Fri, 16 Jun 2023 14:54:36 +0000</pubDate>
      <link>https://forem.com/hisudip_/response-compression-in-a-net-core-api-3pje</link>
      <guid>https://forem.com/hisudip_/response-compression-in-a-net-core-api-3pje</guid>
      <description>&lt;p&gt;By enabling response compression, you can reduce the size of the responses sent by your API, improving network efficiency and overall performance.&lt;/p&gt;

&lt;p&gt;Install the package Microsoft.AspNetCore.ResponseCompression&lt;/p&gt;

&lt;p&gt;Configure it as shown in the code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using System.IO.Compression;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCompression(options =&amp;gt;
        {
            options.EnableForHttps = true; // Enable compression for HTTPS requests
            options.Providers.Add&amp;lt;BrotliCompressionProvider&amp;gt;(); // Use Brotli compression
            options.Providers.Add&amp;lt;GzipCompressionProvider&amp;gt;(); // Use Gzip compression
        });

        services.Configure&amp;lt;BrotliCompressionProviderOptions&amp;gt;(options =&amp;gt;
        {
            options.Level = CompressionLevel.Fastest; // Set the compression level for Brotli
        });

        services.Configure&amp;lt;GzipCompressionProviderOptions&amp;gt;(options =&amp;gt;
        {
            options.Level = CompressionLevel.Optimal; // Set the compression level for Gzip
        });

        // Other service configurations...
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // Other app configurations...

        app.UseResponseCompression();

        // Other app middleware...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you.&lt;br&gt;
Please follow me for more articles.&lt;/p&gt;

</description>
      <category>api</category>
      <category>dotnet</category>
      <category>cleancode</category>
    </item>
  </channel>
</rss>
