<?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>DEV Community: Malek</title>
    <description>The latest articles on DEV Community by Malek (@amilkardev).</description>
    <link>https://dev.to/amilkardev</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%2F418143%2F920491d5-a6b7-41e1-bfff-0d579c8334e8.png</url>
      <title>DEV Community: Malek</title>
      <link>https://dev.to/amilkardev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amilkardev"/>
    <language>en</language>
    <item>
      <title>Azure Load Testing</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Mon, 18 Dec 2023 21:36:38 +0000</pubDate>
      <link>https://dev.to/amilkardev/azure-load-testing-36f</link>
      <guid>https://dev.to/amilkardev/azure-load-testing-36f</guid>
      <description>&lt;p&gt;Load testing is the process of Identifying potential bottlenecks, weaknesses, and points of failure of an application. It is a critical part of the software development lifecycle, however, it is a challenging one, as it involves setting up various load conditions to detect failures and issues that may occur at different levels of application usage. It mainly measures the responsiveness, robustness, and performance of the delivered application under normal usage as well as anticipated peak conditions.&lt;br&gt;
In this article, we will learn more details about Load testing within the Azure ecosystem, exploring its concepts and configuration parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Azure Load Testing Service Concepts:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What’s Azure Load Testing:
&lt;/h3&gt;

&lt;p&gt;Azure load testing services enable developers and business to conduct comprehensive load tests by assessing application performance and uncovering the enhancements that could be made to have a more resilient application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Load testing Key Concepts:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  JMeter:
&lt;/h4&gt;

&lt;p&gt;It's an open-source software tool, useful for performing load tests by analyzing the functional behavior of software applications and measuring their performance under various conditions. It offers a high degree of flexibility and customizability, which allows users to fine-tune their load tests to specific requirements and scenarios. JMeter test scripts that describe different load profiles (parameters of the different scenarios) could be imported into Azure load testing service and implemented on the Azure infrastructure.&lt;/p&gt;

&lt;h4&gt;
  
  
  Test engine instance:
&lt;/h4&gt;

&lt;p&gt;It's an infrastructure computing resource, located in the same location of the azure load testing resource, managed by Microsoft, and runs the Apache JMeter test script, the number of engine instance used for a test are part of the configuration of the test case, as it affects the number of virtual users.&lt;br&gt;
When running the test script, logs generated by the Apache JMeter worker are collected and aggregated by the Azure load testing service to be provided at the end of the test for analysis.&lt;/p&gt;

&lt;h4&gt;
  
  
  Virtual users:
&lt;/h4&gt;

&lt;p&gt;In Apache JMeter, it's referred to as threads, and a pool of virtual users is referred to as Thread Group. Each virtual user runs a particular test case against the server application independently of the rest of the threads.&lt;br&gt;
However, managing the number of virtual users is not all the time controlled directly, it could also be done through the number of test engine instances. The formula to calculate the total number of virtual users is the following: &lt;br&gt;
Total virtual users = (virtual users in the JMX file) * (number of test engine instances)&lt;/p&gt;

&lt;h4&gt;
  
  
  Traffic simulation:
&lt;/h4&gt;

&lt;p&gt;Azure load testing helps developers simulate different use cases with varying number of users as well as number of server instances, all while keeping an eye on the system response to the changes of the simulated environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Throughput:
&lt;/h4&gt;

&lt;p&gt;Known also as Requests per second (RPS), it's an indicator of the number of requests that the load test service forwards to the server application in a second , it's the number of requests divided by the total execution time in second.&lt;br&gt;
Developers should take into consideration that total execution time includes pauses in between threads if the Jmx test script includes timers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Performance evaluation:
&lt;/h4&gt;

&lt;p&gt;Azure load testing service measures different types of indicators including response times, throughput, resource utilization and other key performance to ensure the app benchmarks meet the requirements. We can identify two types of metrics: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Server-side metrics:&lt;/em&gt; Since the Azure load testing service integrates with Azure Monitor services, we will be able to see logs captured depending on the running service (specific message logs defined in the application, resource consumption, database queries or HTTP requests) &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Client-side metrics:&lt;/em&gt; Results delivered by the test engine, includes all the test aspects: number of virtual users, number of requests per second, number of succeeded/failed requests, and much more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfnx6qcy5fyzrr7c5h0b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfnx6qcy5fyzrr7c5h0b.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Load testing configurations:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Load Profiles:
&lt;/h3&gt;

&lt;p&gt;Defining different scenarios that mimic the intensity of user interactions and the various use cases of the application as well as the frequency of requests. It allows a more comprehensive and realistic test environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh5d055kk3wzeqkbjtp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh5d055kk3wzeqkbjtp5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Network conditions:
&lt;/h3&gt;

&lt;p&gt;Simulating conditions such as latency, bandwidth and protocols help visualize the application performance under specific network constraints.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test durations:
&lt;/h3&gt;

&lt;p&gt;It represents the time span during which the load test is being conducted, may vary from seconds to days, and it's an important factor of the load testing as it helps developer test the functioning of the application under sustained load for extended periods of time (stress tests) by detecting any degradation or issues that may occur over time.&lt;/p&gt;

&lt;h3&gt;
  
  
  RampUp time
&lt;/h3&gt;

&lt;p&gt;In the context of load testing, the ramp up times is the duration it takes to embark all the virtual users of the load test gradually, it essentially controls how quickly the users start interacting with the application being tested. It aims to simulate the scenario where the users load increases gradually instead of instantaneously reaching the maximum capacity.&lt;br&gt;
For example, if we have 5 users in the subject test, and we want a new user to join the app each 5 seconds, the ramp up time will be 5*5=25 seconds&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff89av2424xwmqmrtxde1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff89av2424xwmqmrtxde1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Load testing in Azure:
&lt;/h2&gt;

&lt;p&gt;For this example, we will need an active azure subscription as well as the right RBAC role that allows creating and managing resources in the subscription (Contributor/Owner)&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Azure load Testing resource:
&lt;/h3&gt;

&lt;p&gt;After signing up and filtering the Azure Load testing service from the search field, you can proceed to creation of the service by configuring the subscription, Resource Group, Name, and location. Finally, you may hit the create button to provision your resource.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Azure Load Test:
&lt;/h3&gt;

&lt;p&gt;To proceed with the testing, we need to specify a specific URL of the application or service that will be tested, and either upload a JMeter script that contains the configuration and load profiles of the test or configure those details manually in Azure. For this example, we will opt for the latter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring the tests load profile:
&lt;/h3&gt;

&lt;p&gt;With Azure load testing service configuration, we may define load profile via number of virtual users or Requests Per second (RPS).&lt;br&gt;
Once you have made your choice about the load type, you will need to setup parameters configuration based on your choice, if we proceed with virtual users, we will need to fill in the form with the number of virtual users, test Duration and the Ramp-Up time.&lt;br&gt;
Azure Load testing will automatically create an Apache JMeter script for the load test based on the configuration we just done; you may download the script from the test run on the dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzaa2ufqdovkfhey1wfp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzaa2ufqdovkfhey1wfp3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: instead of setting up the test parameters on the dashboard, we can set the configuration in JMeter script file and upload it to the azure load testing service.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monitoring test results:
&lt;/h3&gt;

&lt;p&gt;Once the test starts, we will get a dashboard that streams the client-side metrics being refreshed every five seconds. Th dashboard offers multiple options and filters to adapt the graphs to display different metrics, aggregate or filter them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa74g2dafwx13imkpfnyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa74g2dafwx13imkpfnyq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating Azure Load Testing in CI/CD pipelines:
&lt;/h2&gt;

&lt;p&gt;Automated load testing could easily be integrated into the deployment process using Azure Dev-Ops, as it allows to run the load tests after each commit or before each release to make sure that the delivery will be able to handle the use cases covered in our load test.&lt;/p&gt;

&lt;p&gt;Before dipping our toes into the configuration of the pipeline, we need to make sure our setup includes the following requirements: An active Azure subscription, an account with the role of application administrator, an Azure DevOps project and organization that is connected to Microsoft Entra ID, and a load testing resource.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Steps:&lt;/em&gt;&lt;br&gt;
From the load test resource interface, we click on the Set up CI/CD option and fill in the form details with the organization, projects, repository and branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ycvbpqgqzoz1nsljy3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ycvbpqgqzoz1nsljy3n.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Once the pipeline creation finishes, a notification will show up in your Azure portal with a link to the pipeline, from which you can run the pipeline /modify its steps or triggers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukitw8nkaql5zvwbou1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukitw8nkaql5zvwbou1b.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
When you access the pipeline and try to run it, you will need to install Azure load test from visual studio marketplace and assign the pipeline the permission to access the load test resource, once done, the CI/CD pipeline starts running the test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5yc25tfe1j0uk3gwang.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5yc25tfe1j0uk3gwang.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Finally, you will be able to see the logs of the tests and its results in the pipeline artifact, and you may also download it for further analysis.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgruwkd7ol18juq8644w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgruwkd7ol18juq8644w.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Ensuring the best possible performance in a variety of use cases, load testing is one of the pivotal options that we should consider. Through an extensive presentation of load test concepts, and its integration in Azure as well as including it in the CI/CD pipelines, this article provides developers with the necessary knowledge to run load tests inside an Azure environment. A knowledge that is much needed in today’s digital landscape, where seamless integration of load tests into the projects pipeline is becoming an essential part of the development workflow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>C# Delegates :Types and usage</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Thu, 02 Nov 2023 22:51:20 +0000</pubDate>
      <link>https://dev.to/amilkardev/c-delegates-types-and-usage-3nlm</link>
      <guid>https://dev.to/amilkardev/c-delegates-types-and-usage-3nlm</guid>
      <description>&lt;p&gt;If you are in the process of learning or developing in C#, you will certainly stumble upon cases of passing a method as a parameter, all while applying programming concepts such as polling, callbacks, and techniques such as Linq. In this case, you certainly worked with the C# delegates. In this article we'll delve into the details of this concept for a better understanding.&lt;/p&gt;

&lt;p&gt;To download the source code for this article, you can visit our GitHub repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delegates Declarartion :&lt;/strong&gt;&lt;br&gt;
In C#, delegates represent a reference type that points to a method with a specific signature. They can be declared within a class or independently, as shown in the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace DelegatesDemo.DelegateAppl {
    public delegate string FirstDelegate (int x);
    public class Sample {
        public delegate void SecondDelegate (char a, char b);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's instantiate some delegates and use them to refer methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace DelegatesDemo.DelegateAppl
{
    delegate int ValueSubstitute(int n);
    public static class DelegateDemo
    {
        delegate int ValueUpdate(int n);
        static int Value = 10;
        public static int CurrentValue()
        {
            return Value;
        }
        public static int SumOperation(int p)
        {
            Value += p;
            return Value;
        }
        public static int MultOperation(int q)
        {
            Value *= q;
            return Value;
        }
        public static void RunDelegate()
        {
            ValueUpdate update1 = new ValueUpdate(SumOperation);
            ValueUpdate update2 = new ValueUpdate(MultOperation);


            update1(25);
            Console.WriteLine("Value of Num: {0}", CurrentValue());
            update2(5);
            Console.WriteLine("Value of Num: {0}", CurrentValue());
            Console.ReadKey();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We defined two instances of the ValueUpdate delegate. The first delegate is used to get two integers' sum. The second delegate represents the multiplication operation of two integers.&lt;br&gt;
Delegates allow developers to handle methods the same as objects, passing them as parameters, invoking them dynamically, and assigning them to variables. With all these usage scenarios, Microsoft took it a step further providing more specific types of delegates, the Func, Action, and Predicate.&lt;br&gt;
&lt;strong&gt;C# Func:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Func represents the delegates that could take one or multiple Input parameters, and return a value. Its declaration depends on the number of parameters the referenced method could take :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Case of  no input parameter : Func &lt;/li&gt;
&lt;li&gt;Case of one input parameter: Func&lt;/li&gt;
&lt;li&gt;Case of two input parameters: Func&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Func delegate in C# could take up to 16 input parameters, besides the TResult which represents the return type of the referenced method, and it does not allow ref and out parameters.&lt;/p&gt;

&lt;p&gt;Below, we define and make use of a couple of Funcs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static Func&amp;lt;int, int, int&amp;gt; intMultiplyFunc = delegate (int a, int b)
{
    return a * b;
};

int intMultResult = intMultiplyFunc(15, 1);
Console.WriteLine(intMultResult);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example shows the usage of a Func with an anonymous method, which takes two integers and returns their multiplication result.&lt;/p&gt;

&lt;p&gt;The next example shows the usage of a Func with a lambda function that takes two integers and returns their sum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Func&amp;lt;int, int, int&amp;gt; intSumFunc = (a, b) =&amp;gt; a + b;
int intSumResult = intSumFunc(5, 3);
Console.WriteLine(intSumResult);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;C# Action:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similar to the Func concept, Action is a built-in generic delegate that represents one or many methods. It could be defined with an anonymous or lambda function. However, it is limited to methods with no specific return type. It only represents a method with the return type set to void.&lt;br&gt;
We'll define an example of Action that is representing an anonymous method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Action&amp;lt;string&amp;gt; displayName = delegate (string name)
{
    name = name.ToUpper();
    Console.WriteLine($"Hello, {name}!");
};

displayName("Code Maze");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The displayName delegate in this case takes a string as an argument and makes use of it as per the user requirements: Converting it to uppercase and displaying it. The logic in this case is in the form of an anonymous method, which is a convenient way to write logic that is rather short and not redundant throughout our application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C# Predicate:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Getting more specific with delegates, Predicates is the delegate representing a method that takes only one input parameter and returns only a boolean type. It is useful when defining a couple of conditions to be checked against the input parameter and returns a boolean value representing whether those criterias were met or not.&lt;br&gt;
Below is an example of a predicate that represents a classic C# method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static bool IsLowerCase(string str)
{
    return str.Equals(str.ToLower());
}
public static void RunPredicate()
{
    Predicate&amp;lt;string&amp;gt; isUpper = IsLowerCase;


    bool result = isUpper("hello world!!");
    Console.WriteLine(result);
    Console.ReadKey();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Predicate example checks whether a provided string parameter is lowercase or not. As mentioned, it takes only one parameter(string type in this case) and returns a boolean value. It is worth noting that predicates could also be defined using anonymous and Lambda expressions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we delved into one of the most useful C# aspects: delegates. Covering its various types along with examples to help illustrate and clarify the concept. You will need this technique, especially with Linq, implementing design patterns such as Observer, Strategy, and Visitor or writing functional code in C#.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to approach performance issues II</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Sat, 11 Feb 2023 15:24:06 +0000</pubDate>
      <link>https://dev.to/amilkardev/how-to-approach-performance-issues-ii-38il</link>
      <guid>https://dev.to/amilkardev/how-to-approach-performance-issues-ii-38il</guid>
      <description>&lt;p&gt;Dealing with performance concerns could be an intricated task that transform easily into a story and a sprint of refactoring , testing and code improvements. It's not the best experience you may have as a developer , especially if your team is in a rush and patience is a scarce luxury.&lt;br&gt;
Throughout this article , I will be describing my journey with a similar performance improvement task and how I transformed it into amazing learning experience!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 - Setting up testing environment&lt;/strong&gt;&lt;br&gt;
Simulating your production environment for testing your application is a crucial part of this task , as it helps gaining time, having a better visibility on the improvements you are making and excluding solutions that introduce more code complexity than gained milliseconds in terms of latency ! If you need more details about this step, you may refer to &lt;a href="https://dev.to/amilkardev/how-to-approach-performance-issues-4afh"&gt;the following article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2 - Identifying bottlenecks in your code&lt;/strong&gt;&lt;br&gt;
This is a strategic step toward fixing performance issues , because it helps identify improvement plans that will affect most of your endpoints at the same time. to do that , you start by identifying the methods/code logic that are referenced by multiple endpoints , and you focus on them , to check if there is any refactoring or code cleaning to be done. &lt;br&gt;
Identifying the "start with" points is critical to build your strategy of performance enhancement, once you identify them, you proceed with the following steps :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if there is any obvious improvements to be implemented &lt;/li&gt;
&lt;li&gt;Benchmark those methods to check their latency (using Benchmark.Net Library or the Time attribute of &lt;a href="https://www.nuget.org/packages/MethodTimer.Fody" rel="noopener noreferrer"&gt;MethodTime.Fody library &lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Searchand assess improvement options along with running tests to measure the enhancemnts!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/em&gt; : While working on a Api improvement , I started by identifying the a method that implements authorization logic , and it was referenced by almost any of the API endpoints. Refactoring and optimizing this methods' logic , helped a lot with improving the overall performance of the API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 - Look at the bigger picture&lt;/strong&gt;&lt;br&gt;
By this I mean , the real big picture , which includes your dev environment , your prod environment , your database management system , your ORMs, and the frameworks you are integrating into your application (if any !)&lt;br&gt;
If a query seems to be slow for no specific reason , even when its logic is straightforward , It's a good idea to try running it on a different environment.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/em&gt; : We had a local dev environment composed of visual studio 2022, SQL Server , Redis Microsoft Azure storage Emulator ., and while testing the performance of an endpoint , the SQL profiler shows that a simple query was taking a couple of seconds to execute although it was a simple Select with only one filtering condition! Testing this same query on the Azure db was taking less than 5 ms , which made us question the environment and the area of code we were testing , and it seems that memory issues could cause similar problematic situations , expecially if you are debugging a heavy solution in visual studio and it is running along with an instance of SQL Server on the same machine instance ( a better description of this situation is in this &lt;a href="https://stackoverflow.com/questions/64637132/sql-server-slow-after-debugging-website-in-visual-studio[](url)" rel="noopener noreferrer"&gt;stackoverflow post&lt;/a&gt; ). Having such kind of outlook on the situation could help you avoid lots of time investigating issues locally inside your code , while the main concerns are in the environment as whole!&lt;/p&gt;

&lt;p&gt;The second path that you should explore in the process of performance checks is the way your are connecting your application to database , certainly there is plenty of choice when it comes to that , so you may be using an ORM ( EF Core, Dapper , Nhibernate ...) , or you may be relying on Simple queries and stored procedures. When working on performance , you should take those choices in consideration , how advanced is your application , and how deep it goes into implementing any of the previous options , comparing those options while taking in account the type / quantity of data you will be handling , considering the choice of adopting one instead of the other , testing some slow methods using a different db connection approach to see if that improves performance and in case of success, should you consider adopting the newly adopted method instead of the previously slow one ? all those are question you should answer and discuss with your team and client, based on the size and the advancement of the application !&lt;/p&gt;

&lt;p&gt;Once you are comfortable with the choices you have made for your application ( Frameworks and libraries ) , or even if not , may be you are at the point where you cannot go back and start over with new options, in both cases , you still have alternatives . For example in the case of using EF Core , there is a couple of practices and methods you could adopt for you handle performance issues , you may also want to check the generated SQL of this ORM and find ways to implement it further !&lt;/p&gt;

&lt;p&gt;Finally , if you are using frameworks that generate code , or setup the project structure for you ( Example of those are ABP framework ), you should double check the documentation of that framework ,looking for recommendations and best practices in there about performance and considerations. Besides if those frameworks are used to generate a boilerplate code for entities or CRUD operations, It's highly advised to thouroughly review this code and put in place a mechanism or code rules that improve and refactor any of the current/future generated code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/em&gt; : using ABP Framework , could be super helpful as it save you the time to write all the boilerplate code for entities,DTOs and Crud operations , not only that , it does generate the code respecting the architecture you have already setup for your project ( Microservices, DDD ...). All seems awesome  until you start the load testing process , and issues start revealing themselves. An example of the issues we had with the generated code was that it makes double db round trip each time we needed to query a list of entities : the first for getting the entities and the second for counting them , which is not a performance friendly approach. For that we had to implement some code refactoring options , and set up some code rule that make sure to fix and chnage these kind of logic everytime we generate new entities using ABP framework.&lt;/p&gt;

&lt;p&gt;With the progress those AI tools are making , Github Copilot, OpenAPI , developers may start relying more on their generated code to save time and speed the process. However , the time we gained , we ought to spend some of it on reviewing the generated code instead of taking it as it is , as advanced those tools are, they are still away from perfect !&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>How to approach performance issues</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Fri, 27 Jan 2023 18:58:44 +0000</pubDate>
      <link>https://dev.to/amilkardev/how-to-approach-performance-issues-4afh</link>
      <guid>https://dev.to/amilkardev/how-to-approach-performance-issues-4afh</guid>
      <description>&lt;p&gt;Hello there , let me guess : you are suffering tasks/endpoints calls  that are taking multiple seconds, but your users are in rush and they couldn't wait that long. so you ought to tackle those latency concerns and you need some recommendations from people who already crossed that path ( and reduced their API calls latency by 80% may be !) . You've come to the right address !&lt;/p&gt;

&lt;p&gt;So the process toward an efficient performance improvement plan includes :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1-Identifying the slowest endpoints&lt;/strong&gt; : &lt;/p&gt;

&lt;p&gt;Usually we start raising concerns about performance when the user is struggling to get some data to show up in a timely manner, so obviously , the main trigger to such investigation is the user experience (Let's hope that the user in your case is the QA and not the actual customer ).&lt;/p&gt;

&lt;p&gt;And since the slowness reported by the user of those specific endpoints could be not related to you application ( could be related to his internet connection bandwidth or his hardware ...), which brings us to the next step !&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2-Make use of monitoring tools&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;They are very useful in terms of having a general overview of how is your API behaving through the usual day to day usage of your API. There is multiple great tools on the market for this purpose , but if your API is deployed in an Azure environment , you should consider Azure Insights and Azure monitoring services , the latter was very useful on grouping / Filtering all API calls based on their timing ( which is what we need in this case) , and a bunch of other parameters. It's an awesome service that I consider the source of wisdom , as it helps find out the slowest endpoints along with many other details that are useful for your investigation( duration of the endpoint call , count of calls...).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcposexidccqzefxplky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcposexidccqzefxplky.png" alt="Image description" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If Azure is not a viable option for your case , then you should consider other external tools options , I had an experience with Prefix tool , A great monitoring solution , especially for performance related investigations : its options include but not limited to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detecting all API calls throughout your navigation journey &lt;/li&gt;
&lt;li&gt;Filtering the registered API calls&lt;/li&gt;
&lt;li&gt;API call details : Timing, duration , URL, HTTP response type number of queries related to that API call , timing of each query, SQL queries themselves which is super useful in case you are not very familiar with MS SQL profiler ( even more suitable in case of using an ORM such as EF )
The good news is that all of those options are included in the free version of Prefix, its premium version provides much more advanced options.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzielw6e6ogl79l991yw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzielw6e6ogl79l991yw.png" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3-Reproducing the slowness via benchmarking:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you get into load testing subject , you will get familiar with warmup , outliers, debug/release environments.&lt;br&gt;
 Mainly, the point of this step is to reproduce the slowness we are experiencing in the prod environment , but when you try to do that , it is not easily reproducible , so when you hit a specific endpoint, you find its response timing is few milliseconds, but wait a moment, wasn't this endpoint tagged by Azure monitoring or Prefix  as slow based on the statistics! yes it is , the one and only , so how could I improve /test an endpoint that is already performant ( well, here comes the famous saying , "it works on my machine" if you know what I mean  ;)&lt;br&gt;
Similar to any other bug that you try to fix ( and since you are here , I guess you haven't deal with a few , they are normally your bread and butter ) , so the first step toward finding a solution is to reproduce the problem "On your machine". for that you need to simulate the environment in which this slowness happened and to do that , you will have to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Prepare a database with similar quantity of data to the one in the prod ( or the environment having the slowness issue), simply because you will not be able to reproduce the issue if you are having 15 items in each of your db tables , but the prod tables , each is having thousands of rows. For this process you may consider preparing a script to load the database with a bulk data, and if you are still in the .Net environment , Bogus framework could be of use in this case&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simulate the application state : means selecting the release option in case of .Net apps  , doing an application warmup. Here we go another performance related term !&lt;br&gt;
&lt;strong&gt;Warmup&lt;/strong&gt; is  the step of setting the application on the state READY , in order to get accurate measure of the api calls timing. doesn't an API call have the same behavior throughout the whole application lifetime ? the answer is no , at least not exactly , especially when you get into the details .&lt;br&gt;
First time you run the application and start an API call , there is a load of code to be compiled , dependencies to be loaded and injected , caching to be done , Queries and linq expressions to be compiled , monkeypatched methods /classes that are to be defined/loaded on the fly with reflection or &lt;a href="https://harmony.pardeike.net/articles/intro.html" rel="noopener noreferrer"&gt;Harmony &lt;/a&gt;. All those operations do not happen on every request , they happen mainly at the first 10-100 API calls , and because of that , performance measurment taken on the first calls are not as accurate as the ones done later on the process , and their environment/app state is not similar to the environment/app state in which the user encountered slowness. Therefore , you ought to iterate a couple  hundreds of calls to the API just before hitting it with calls for performance measurments/ slowness reproduction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The slowness reported from the monitoring tools is based on thousands of calls done to a specific endpoint , what's showed up as the call duration is the average of the thousands of calls' durations. so you may consider launching thousands of call ( not manually of course !). For this , you will need a tool to launch such kind of scenarios, again , if you are on the .Net environment, the .Net benchmarking tool &lt;a href="https://benchmarkdotnet.org/articles/overview.html" rel="noopener noreferrer"&gt;BenchmarkDotNet&lt;/a&gt; could be of interest.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What's the point of this tedious setup ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Wise question, you here to find some solutions to the performance issues that you are facing , how does this complicated setup , shouldn't be there some possible solution for you to start the improvement plan ? &lt;br&gt;
Yes , I hear you, there is a myriad of solutions that you could implement for your performance improvement plan, and we will get there in the future articles. However, those improvements plans may not be as effective as you expected ,and you will need a solution to find out whether they are effective or not , and if effective , how effective are they , taking into consideration the complexity they introduce into your code base. Besides, setting up a testing environment is crucial for you to verify if there is any real improvement resulting from a specific implemented logic, because , it is not accurate to check/measure improvements just by trying things out with no defined statistics/result, that way , who knows if there was any real improvement, you know the saying " Data is religion, without data you are just another guy with an opinion".&lt;/p&gt;

&lt;p&gt;Coming to the end of this article , if you still interested in performance improvement plan , keep an eye on for the next articles ! keep hacking&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>claude</category>
      <category>ai</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Mixing Two Blazor component Libraries ( Telerik &amp; Blazorise )</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Thu, 15 Dec 2022 21:43:09 +0000</pubDate>
      <link>https://dev.to/amilkardev/mixing-two-blazor-component-libraries-telerik-blazorise--of7</link>
      <guid>https://dev.to/amilkardev/mixing-two-blazor-component-libraries-telerik-blazorise--of7</guid>
      <description>&lt;p&gt;Lately I have been working on a frontend part of a project that was built in Blazor. The project was mainly built using &lt;a href="https://commercial.abp.io/tools/suite"&gt;Abp Suite&lt;/a&gt; Framework with Blazor server for frontend.&lt;/p&gt;

&lt;p&gt;By default, when you make use of the ABP features of autogenerating CRUD operations endpoints/ interfaces and tests , based on the selected template (In our case , we were using Blazor server with Lepthon theme) , some frontend code will be autogenerated for you for the basic Create/Add/Delete/Update. By default , with blazor frontend themes, the ABP installs/adopts the &lt;a href="https://blazorise.com/"&gt;Blazorise &lt;/a&gt;frontend Component library. &lt;/p&gt;

&lt;p&gt;It's a useful library with plenty of features (80+ free and open source native Blazor UI controls) that helps with building rich blazor interfaces , and it was a nice default add On to the ABP. &lt;/p&gt;

&lt;p&gt;However , since Great ships asks for deep water , same was our ABP application , with the evolving of business requirements , we needed to develop much more complicated forms and interfaces , and yes , it's here where the Blazorise falls short , mainly at Text editor and dynamic tabs components . Then Telerik comes in handy , especially  with the rich pack of component and options , including the Text editor and the Dynamic Tab.&lt;/p&gt;

&lt;p&gt;We went on with Telerik , all while keeping the Blazorise in place , since we couldn't miss all the ABP auto-generated staff that was so useful. Buying a Telerik license and starting to integarte its different components into our code. It went well at the beginning , except some few warning that we didn't care much about. &lt;br&gt;
Always as the requirements get more complicated, the code base gets to grow and complications arise. and the issues now are much more then just few warnings, as we start encountering weird issues such as  :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components not working as expected ( whether it is Blazorise or Telerik ) : for example input validations, Loader ...&lt;/li&gt;
&lt;li&gt;Text editor component of Telerik working fine, but sometimes content gets erased automatically &lt;/li&gt;
&lt;li&gt;hundred of warning about Telerik components not being recognised and sometime Blazorise components.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Found markup element with unexpected name 'TelerikCardBody'. If this is intended to be a component, add a @using directive for its namespace.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n2LEscMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8fr9gylm0ef8k24dojt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n2LEscMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8fr9gylm0ef8k24dojt.png" alt="Image description" width="880" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first we didn't thought having a mix of those two libraries could be the source of those weird issues , we explored multiple paths including filing support tickets to Telerik, but that didn't resolve the issue. &lt;em&gt;And we noticed that testing those components on a standalone projects worked fine.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our mistake was that we were nesting components from different sources , which caused those weird issues to happen and make components not functioning clearly as mentioned in the documentation. If you closely into this small portion of sample code , you will see that we were using Blazorise Grid component , inside of it there was TelerikCardBody component , nested in it the Blazorise TextEdit Component. I wouldn't blame the team as when developing this , we were in a rush and had to get the initial version of the interfaces out. but for sure , that wasn't the smartest decision either.&lt;/p&gt;

&lt;p&gt;At this point , if you are here to know if different component libraries could be mixed in the same Blazor application , probably you got your answer , and it's yes, you can , but get ready for some unexpected component behavior and irritating issues, so take the Yse with a bit of salt , and avoid this if possible, although I doubt that , especially with highly complicated interfaces as not Library is really perfect.&lt;br&gt;
And if you still hungry for learning , or you are just try to find your way out of a similar situation , don't hesitate to read my next article , in which I will explain how we managed to use both of them with no  issues.&lt;br&gt;
With this , we come to the end of this article , I hope you find it useful . Happy Coding &amp;lt;3 &lt;/p&gt;

</description>
      <category>blazor</category>
      <category>telerik</category>
      <category>csharp</category>
      <category>frontend</category>
    </item>
    <item>
      <title>confusing issues with EF Core</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Wed, 16 Nov 2022 07:36:28 +0000</pubDate>
      <link>https://dev.to/amilkardev/confusing-issues-with-ef-core-507</link>
      <guid>https://dev.to/amilkardev/confusing-issues-with-ef-core-507</guid>
      <description>&lt;p&gt;Working with ORMs has been a such a life saver for the developers , It reduces their dependency on SQL knowledge and DB administrators , It helps developer be more productive thanks to the easiness of handling DB operations.&lt;br&gt;
It even limits a number of security vulnerabilities that would cause them headaches if logic implemented with SQL.&lt;br&gt;
Also without ORMS, it could be such a painful task to maintain SQL scripts , indexes, stored procedures especially in this era of continuous integration and delivery.&lt;br&gt;
 But for which cost do reap all these benefits. In this article , I will go through few of the dark sides  of using ORM, my subject for this article is EF Core, which is the ORM I am using in my current project. For that I will go through some of the ambiguous bugs the I faced lately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data may have been modified or deleted since entities were loaded
&lt;/h3&gt;

&lt;p&gt;This issue was quiet interesting for me , since we were early on setting up the basic boilerplate code for our modules , and we were building the initial entities , setting up their Crud operations , and while working on the update endpoint of some entities , I encountered this issue . Seemed weird to me at first because am the only one working on this testing data and it's already working only locally, so no way to have the data modified/deleted by another contributor. in the message error on visual studio output , along with the exception there was a link to Microsoft documentation about&lt;a href="https://learn.microsoft.com/en-us/ef/core/saving/concurrency" rel="noopener noreferrer"&gt; handling concurrency &lt;/a&gt;.&lt;br&gt;
That link wasn't so helpful , because it even made the situation more puzzled. As mentioned in the beginning , we were only setting up the basic CRUD operations ,and we haven't thought nor planned how we are going to deal with concurrency conflicts. &lt;br&gt;
The missed puzzle in this situation is that we were using a Framework name ABP Framework, that would facilitate generating entities , basic logic as well as setting up the general modules structure according to the DDD principles.&lt;br&gt;
What I have missed in this situation was that the entities inherit by default from an AggregateRoot class of the ABP framework , this AggregateRoot class itself implements IHasConcurrencyStamp , which made it obligatory to handle cncurrency stamp conflicts , even if we didn't consider that yet. The issues happens mainly in the following scenario :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We fetch an item from DB with its ID and its specific ConcurrencyStamp ( which was defined by the Framework we adopting for this project , will give it the value XXX)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Update Endpoint of the API takes as parameters the Item Id (Guid type) as well as the ItemUpdateDto, the latter was also generated by the ABP framework and inherits from the AggregateRootDto and have ConcurrecnyStamp property too.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When the call reaches The API update endpoint with the ID and the EntityUpdateDto , the Update loginc goes as below ;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch the item from Db using Id provided ( which brings the item with a new specific Concurrency Stamp YYY)&lt;/li&gt;
&lt;li&gt;Map the ItemUpdateDto to the newly fetched item , so now the newly fetched item has the properties updated as well as the ConcurrencyStamp being updated as well , so now its ConcurrencyStamp is XXX&lt;/li&gt;
&lt;li&gt;Save the modified Item to DB&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Trying to save the Item to DB using EF Core is no longer possible , because the item when fetched , it had the ConcurrencyStamp of YYY , but now we want to save it with a different one ,wich doesn't make sense for EF Core.&lt;/p&gt;

&lt;p&gt;In EF Core , for an entity to be modified and saved it has to keep the same concurrencyStamp throughout the whole process , but in my case , it was changed on the mapping step, which caused this issue What made the situation even more delicate , is the fact that those concurrency Stamps causing this issue weren't intentionally added to to my classes neither they were considered when investigating this issue .&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution :
&lt;/h2&gt;

&lt;p&gt;The solution that I opted for in this situation is to ignore the concurrency stamp property when mapping the ItemUpdateDto to the newly fetched Item at the step just before saving it with the new modifications.&lt;br&gt;
Following the mapping configuration I put in place dor mapping ItempUpdateDto to a concrete Item: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

CreateMap&amp;lt;ItemUpdateDto, Item&amp;gt;()
            .IgnoreAuditedObjectProperties()
            .Ignore(c =&amp;gt; c.IsDeleted)
            .Ignore(c =&amp;gt; c.DeleterId)
            .Ignore(c =&amp;gt; c.DeletionTime)
            .Ignore(c =&amp;gt; c.ExtraProperties)
            .Ignore(c =&amp;gt; c.ConcurrencyStamp)


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

&lt;/div&gt;

&lt;p&gt;Below is the code for the Update endpoint ;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

public virtual async Task&amp;lt;ItemDto&amp;gt; UpdateAsync(Guid id, 
        ItemUpdateDto input)
 {
      var item = await _itemRepository.GetAsync(id);
      ObjectMapper.Map(input, item);
      var returnItem = await _itemManager.UpdateAsync(id, item);
      return ObjectMapper.Map&amp;lt;Item, ItemDto&amp;gt;(returnItem);
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Database operation expected to affect 1 row(s) but actually affected 0 row(s)
&lt;/h3&gt;

&lt;p&gt;With this one ,the exception message also provided a link to official documentation about handling optimistic concurrency exceptions , but I checked concurrency stamps for the update operation and it was matching as required , so why this specific error message. It didn't reveal much of details , and I was stuck for quite some time. &lt;br&gt;
What saved me was changing the way I investigate this kind of issues , so instead of jumping around the LINQ expressions code and the different steps of logic to see what's causing this issue ( which obviously was not working) , I opened SQL profiler to see what are the queries generated by EF Core , and I looked into each of them , they were looking perfect.&lt;br&gt;
I pasted those queries in SQL server and tried to run them , and here the issue appears , which apparently was related to a foreign key constraint that was not valid. I was inserting/Updating a player row into the the players table , in the data I am sending there was a field named TeamId , which was a foreign key referencing the teams table. That foreign key was not valid as it didn't exist in the teams table. But could you have guessed that from the exception message , for me it was almost impossible to spot.&lt;/p&gt;
&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;This way to investigating EF Core issues is the best when the issue happens at the EF call of saving data to DB,  and the steps are as mentioned below :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open SQL profiler from SQL server Management System , from Tools &amp;gt; SQL server Profiler&lt;/li&gt;
&lt;li&gt;Spot the queries shown up upon hitting the endpoint causing the issue &lt;/li&gt;
&lt;li&gt;Copy these queries and try to execute them on SQL server&lt;/li&gt;
&lt;li&gt;If there is issues with the data you are inserting/Updating , SQL server will be more verbose about it , it will point exactly to the constraint , trigger or index causing the issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of course , in this description SQL server is what I was using when investigating this issue , but surely you could try the same process with the DBMS you are using and its own profiler.&lt;/p&gt;

&lt;p&gt;If you don't want to use a profiler at all , you could use Stackify Prefix in its free version , it's an awesome tool that displays all the SQL queries created by EF Core , as well as their timing and much more details.&lt;/p&gt;
&lt;h3&gt;
  
  
  EF Core ; Two foreign key referencing the same table
&lt;/h3&gt;

&lt;p&gt;Implementing some kind of API design in C# code lately has put me in situation where I needed the same table to be referenced two times in one class. For the sake of this article , we'll set the example of class , having two teachers : principle and substitute:&lt;br&gt;
A class should have at least one principle teacher , 0 or 1 substitute teacher , and a teacher may be assigned to multiple classes&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzckjh7szcdt8m3c5tr0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzckjh7szcdt8m3c5tr0v.png" alt="diagram class of code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To implement this relationship I opted initially for one to many relationship between class and teachers which I realized soon that it is not the right way to implement this, then I kept experimenting with the configuration of the entities in Fluent API , trying to make them created as required in the design , by just Fluent configuration , but in vain. &lt;/p&gt;
&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;What I ended up doing on the entities implementation is the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

public class Class
     {

        public Guid Id { get; set; }
        public List&amp;lt;Student&amp;gt; Students { get; set; }
        public Guid principalTeacherId { get; set; }
        public Guid substituteTeacherId { get; set; }

        public Teacher principalTeacher { get; set; }
        public Teacher substituteTeacher { get; set; }
      }

public class Teacher
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Degree { get; set; }
        public int Age  { get; set; }
        public string SubjectName { get; set; }
        public bool IsPrinciple { get; set; }
        public bool IsSubstitute { get; set; }

        //Classes for which the teacher is a substitute
        public List&amp;lt;Class&amp;gt; SubstituteClasses { get; set; }
        //Classes for which the teacher is a principle
        public List&amp;lt;Class&amp;gt; PrincipleClasses { get; set; }
     }


public class Context : DbContext
{
    ...

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity&amp;lt;Class&amp;gt;()
                    .HasOne(m =&amp;gt; m.PrincipalTeacher)
                    .WithMany(t =&amp;gt; t.PrincipleClasses)
                    .HasForeignKey(m =&amp;gt; m.principalTeacherId )
                    .WillCascadeOnDelete(false);

        modelBuilder.Entity&amp;lt;Class&amp;gt;()
                    .HasRequired(m =&amp;gt; m.substituteTeacher)
                    .WithMany(t =&amp;gt; t.SubstituteClasses)
                    .HasForeignKey(m =&amp;gt; m.substituteTeacherId )
                    .WillCascadeOnDelete(false);
    }
}


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

&lt;/div&gt;

&lt;p&gt;All this makes sense especially the way the Class entity is set , but what I missed at the beginning was the fact I should have two Collection of classes in the Teacher entity . Setting that made relationship &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Still many more issues that I had to handle to implement all kinds of designs in EF Core Code first that I will be sharing continuously in this blog, so if you find ths subject interesting , keep an eye on the next articles. I hope you are enjoying this learning journey , keep coding !&lt;/p&gt;

</description>
      <category>ef</category>
      <category>csharp</category>
      <category>orm</category>
    </item>
    <item>
      <title>Error Logging in to Azure Container Registry : Requested access to the resource is denied</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Tue, 30 Jun 2020 01:00:27 +0000</pubDate>
      <link>https://dev.to/amilkardev/denied-requested-access-to-the-resource-is-denied-4ie1</link>
      <guid>https://dev.to/amilkardev/denied-requested-access-to-the-resource-is-denied-4ie1</guid>
      <description>&lt;h2&gt;
  
  
  steps of pushing Docker image to Azure Container Registry
&lt;/h2&gt;

&lt;p&gt;Following up the &lt;a href="https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal"&gt;documentation&lt;/a&gt;, the first steps that I went through are displayed below  :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign in to Azure&lt;/li&gt;
&lt;li&gt;Create a container registry&lt;/li&gt;
&lt;li&gt;Log in to the registry &lt;/li&gt;
&lt;li&gt;Push image to the registry&lt;/li&gt;
&lt;li&gt;List container images&lt;/li&gt;
&lt;li&gt;Run image from the registry&lt;/li&gt;
&lt;li&gt;Clean up resources&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the third step, following the instructions  of the documentation as shown below, it specifies the rule as following " &lt;strong&gt;(Specify only the registry name when logging in with the Azure CLI. Don't include the 'azurecr.io' suffix.)&lt;/strong&gt; " &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KRbf5YM---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/77klzzo2njb0w096qu7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KRbf5YM---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/77klzzo2njb0w096qu7h.png" alt="documentation screenshot" width="880" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That instruction may have worked for some developers, but it cost me half a day logging in and out of azure, restarting docker, and trying all kinds of tips and tricks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What went wrong ?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;"Denied : Requested access to the resource is denied"&lt;/strong&gt;, such an error may delay your production plans if not treated wisely. Trying to test some functionalities on azure container registry (ACR), I created a basic docker image, and followed the official documentation of Microsoft in order to push it into the registry ( already created). Do you think everything worked like charm, Nah! If it did, you won't be reading this article ;) Instead, I got this disturbing error :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Icc27rvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9ccexzkhckfkpplbxumr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Icc27rvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9ccexzkhckfkpplbxumr.png" alt="Alt Text" width="880" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I fixed this ?
&lt;/h2&gt;

&lt;p&gt;The solution was to use the whole registry name including the &lt;strong&gt;azurecr.io&lt;/strong&gt;, contrary to what's specified in the documentation. The commands that worked for me are specified below  :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;h5&gt;
  
  
  docker login yourregistry.azurecr.io
&lt;/h5&gt;

&lt;p&gt;After running this command, you will need to enter your container registry username and password, you will find them on the &lt;strong&gt;Access keys&lt;/strong&gt; tab under settings section of the container registry home page. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;h5&gt;
  
  
  docker image tag imagename:[version] registryname.azurecr.io/imagename:[version]
&lt;/h5&gt;&lt;/li&gt;
&lt;li&gt;&lt;h5&gt;
  
  
  docker push registryname.azurecr.io/imagename:[version]
&lt;/h5&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After using those commands, I was able to push my images to the Azure container registry, but still don't know why Microsoft does specify that rule in the documentation, and whether it worked for some developers ( without adding the ".azurecr.io" ).&lt;/p&gt;

&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;Continuing my learning journey with Azure Container Registry , I found out that the &lt;a href="https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli"&gt;documentation&lt;/a&gt; written on 2019 and not updated on the first months of 2020 (  the documentation mentioned above is updated on first months of  2020) , is using the full version of the Azure Registry Container ( RegistryName.azurecr.io ) , so may be this error is related to the version of CLI , am not sure , but I will continue ivestigating this issue whenever I have time. Meanwhile , keep coding and conquer the bugs &lt;/p&gt;

&lt;p&gt;More information on the next articles will be provided about the task I was working on when I ran into this issue.  If you are using the Azure Container Registry , you may have a comment about the solution or the documentation , please leave it below , and Thanks for reading so far , I hope you learned something new and that this fix works for you.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>docker</category>
    </item>
    <item>
      <title>Error: Resolve-Url-Loader : CSS error</title>
      <dc:creator>Malek</dc:creator>
      <pubDate>Sun, 28 Jun 2020 18:08:49 +0000</pubDate>
      <link>https://dev.to/amilkardev/error-resolve-url-loader-css-error-11ah</link>
      <guid>https://dev.to/amilkardev/error-resolve-url-loader-css-error-11ah</guid>
      <description>&lt;p&gt;The famous Resolve Url Loader, a weird issue that I ran into while trying to run a react project for the first time on my newly installed development environment. If you are curious about all these details, you may refer to this &lt;a href="https://dev.to/amilkardev/first-month-of-internship-1g"&gt;article&lt;/a&gt; to read about the circumstances in which I ran into this error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcbf49jcvlvxvskwbf9cy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcbf49jcvlvxvskwbf9cy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, such errors would push you to start thorough and deep research on the web to know about the why and when and more importantly, the HOW solve it. I already did that, and after trying most of the suggestions, although they worked for some developers, they didn't work in my case. The way I resolved this issue in my project was pretty unique, and that's why I chose to share it in my blog.&lt;/p&gt;

&lt;p&gt;I am glad you are here and I hope you find this content useful. Without further ado, let's get to the solution!&lt;/p&gt;

&lt;p&gt;since I was trying to run an existing project that I just clone from Github, I ran all the required commands such as :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yarn install &lt;/li&gt;
&lt;li&gt;Yarn upgrade&lt;/li&gt;
&lt;li&gt;yarn add react-scripts&lt;/li&gt;
&lt;li&gt;Yarn Build &lt;/li&gt;
&lt;li&gt;Yarn start&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once I started the project this issue showed up every time, no matter what fixes I tried, so I went back to read the files line by line. Going through the Package.json file, I remarked that some of the packages weren't upgraded, specifically the &lt;a href="https://www.npmjs.com/package/react-scripts" rel="noopener noreferrer"&gt;react-scripts package&lt;/a&gt;. It's a set of scripts provided by the create-react-app starter pack, which enables launching React apps without much configuration. This capability comes in the form of multiple features, that include the auto prefixed CSS. And if you read the error details carefully, you will see that the issue is revealed on one of the CSS files. Of course, as part of the error investigation, I changed the CSS files links, I uninstalled, reinstalled, updated the node-sass and the resolve-URL-loader package, but to no avail.&lt;br&gt;
To begin with, let's discover the CSS Autoprefixer , what's it, and what does it? and why is it stopping us from successfully building our newly created/cloned project?&lt;/p&gt;

&lt;h2&gt;
  
  
  What's CSS AutoPrefixer?
&lt;/h2&gt;

&lt;p&gt;It is a CSS post-processor that parses the compiled CSS files checking it against &lt;a href="https://caniuse.com/" rel="noopener noreferrer"&gt;caniuse&lt;/a&gt; service to manage the prefixes related to each vendor. &lt;/p&gt;

&lt;h2&gt;
  
  
  What's the Autoprefixer role?
&lt;/h2&gt;

&lt;p&gt;It solves the problem we encounter with vendor prefixes that we have to apply to the CSS rules to make some options styles available for a larger variety of users on different browsers.&lt;br&gt;
If that seems like a hard explanation, here it is short and clear: Autoprefixer is taking care of your CSS code, which prevents you from remeberance/add/remove/ check of vendor prefixes.&lt;/p&gt;

&lt;h2&gt;
  
  
  what's the issue with the Autoprefixer?
&lt;/h2&gt;

&lt;p&gt;when starting a new React project, you will need to install a react-scripts package, which includes the resolve-URL-loader package, the latter role includes management and redirection of the CSS files. connecting the dots, we may understand that the management operation of the CSS files includes the auto prefixing service. Previous versions of the resolve-URL-loader package used to make use of the &lt;strong&gt;Rework&lt;/strong&gt; CSS parser, but as it's not adapted to manage the modern CSS versions, the package of interest adopted the &lt;strong&gt;PostCSS&lt;/strong&gt; parser by default. Long story short, the subject issue was the result of the bad configuration and management of CSS files caused by the Resolve-Url-Loader, itself included in the react-scripts package. Since my development environment was newly installed. I was using the latest version of yarn and upgrading all the packages, which caused the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I resolved the situation?
&lt;/h2&gt;

&lt;p&gt;Reading the Package.Json file with a fine-tooth comb, I figured out that I was not using the same react-scripts that my team was using on the subject project. Uninstalling the existing react-scripts package and installing the right one served me well. &lt;/p&gt;

&lt;p&gt;So here comes the end of my issues with the frontend project, that I built and start successfully. A sigh of satisfaction was about to rise from the bottom of my heart, but it didn't, because the Backend project developed using C#, which was running flawlessly, was launching a new message error, that took almost two days to find a fix, and the solution, was not more common than the one described in this article.&lt;/p&gt;

&lt;p&gt;Thank you for reading so far, and if you are willing to learn about the next bug with the .Net project, just click on the next article.&lt;/p&gt;

</description>
      <category>react</category>
      <category>computerscience</category>
      <category>webdev</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
