Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

EF - The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet

when you try to generate the EF context for SQL database using the "Scaffold-Context" command in EFCore. But you're getting the following error :
Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try 
again.



Solution:

Just install the following "Microsoft.EntityFrameworkCore.Tools" from Nuget by using the following command

Install-Package Microsoft.EntityFrameworkCore.Tools


or right click on the project and select "Manage Nuget Packages" and type in search "Microsoft.EntityFrameworkCore.Tools" select Microsoft.EntityFrameworkCore.Tools like the below image and install.



Use StringBuilder or string class for concatenating strings





when you want to concatenate strings you'll think about performance so,
Is StringBuilder faster than strings when concatenating or not ?



StringBuilder is the best performance for a concatenation if an arbitrary number of strings are concatenated, however,  the String class is preferable for a concatenation operation if a fixed number of Strings are concatenated.

Note :
You also need to keep in mind that a new string is created at each concatenation when standard string
concatenation is used.so, think about the number of objects that will be created in memory so,
 This can lead to an explosion of objects for the garbage collector to deal with.

Change Datagridview Odd and even rows color C#





You can change Datagridview odd and even rows color by adding this code
C#:

  foreach (DataGridViewRow row in dataGridView1.Rows)
  {
            if (row.Index % 2==0 )
            {
                row.DefaultCellStyle.BackColor = Color.Green;    
            }
            else
             {
                row.DefaultCellStyle.BackColor = Color.LimeGreen;
              }

   }


or you can use AlternatingRowsDefaultCellStyle from designer

or by code :


dataGridView1.RowsDefaultCellStyle.BackColor = Color.Green;

   dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LimeGreen;




Featured Post

Convert Json to Classes

Followers