Tuesday, May 17, 2022

EF irrelevant error when creating migration It was not possible to find any compatible framework version

 When adding a migration you may get following error: 

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
- The following frameworks were found:
3.1.22 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.



Please note that this error is totally wrong and irrelevant. This is not an error of framework version, but error of path declarations. 


The best way to resolve this error is  

1. Make the Web API project a startup project. 

2. Select the project where DBContext resides as default in PM console. 

3. In PM Console, navigate to the path of Web API project. 

4. Now give the following command : 

dotnet ef migrations add NameOfYourMigration --project  ..\PathOfDbContextProject\DbContextProject.csproj


Remember the command "dotnet ef migrations add"  some people forget to write "migrations" , they write "migration" instead. 


Sunday, May 15, 2022

for ref

 what is proxy.conf.ts 


what is @ViewChild and @ViewChildren



What is parallel.ForEach 


What is Plinq


How can we check the query generated by entity framework ? 

What is global assembly cache ? 


What is CLR and CTS ? 


These are parts of a larger specification called CLI (common language infrastructure) 


CLI consists of: 

1. CTS 

2. Metadata (PE files specification - portable executables) 

3. CLS (Common Language Specification)  - common set of  features that every CLI compliant language must expose

4. VES (Virtual Execution System) - CLR 

All the CLI compliant languages are statically compiled to CIL (Common Intermediate Language) code 

CLR JIT compiles CIL to native code, caches the code and executes it. 

High Level Code to CIL -> static compilation  (generates dlls , 

or if Portable options is selected generates PE file for 32 bit, PE+ for 64 bit)

CIL to native code -> JIT compilation by CLR

AOT compiler-> translate IL to machine code -> can better optimize code

JIT compiler ->  translate IL to machine code 

There are two versions of CLR : CLR and CoreCLR. CoreCLR can JIT for targets such as Windows, linux and macOS.

CLR Handles memeory management and garbage collection. 


Which are the languages supported by CLI/CLR ? 

C#, VB.NET , Python/PASCAL ports are also available.



Which are the types supported by CTS ? 

Classes

Structures

Enumeration

Interfaces

Delegates


Are delegates type  safe than a function pointer ? how ? 

Delegates are guranteed to be refer to  a valid method with correct signature, a pointer can mistakenly be assigned to something else also. 

Secondly delegates can bind to a method of an object , rather than a class. 



The type double in C# is a floating point type. How do classify C# numeric types 

in floating and fixed point types ? 



Is EntityFramework (or Dbcontext) thread safe ? 

No. EF /DbContext are safe only when each thread uses separate Dbcontext. 

So if you are using DbContext in Parallel.ForEach loop, better to instantiate 

a new DbContext on every iteration. 

=============================================================================

https://www.codemag.com/article/1407051/Python-for-C#Back2article

Python for C# Developers  By Michael Kennedy 

A very important article comparing features of Python and C#


https://www.red-gate.com/simple-talk/development/dotnet-development/10-reasons-python-better-than-c-sharp/

10 reasons why Python is better than C# (or almost any other programming language)

By Andy Brown

=============================================================================

What is Task Parallel Library ? 

Most of the desktops/laptops in today's scenario use multicore CPUs. 

The true adavantage of multicore CPUs can only be taken when the we can run 

tasks simultaneously on multiple cores. 

C# provides parallel computing through TPL. 

TPL provides two types of parallelism : 

Data Parallelism : 

Parallel.For method 

Parallel,ForEach method

Task Parallelism: 

Parallel.Invoke


What types of tasks can be executed parallely ? 

For parallel execution : 

Tasks should be independent of each other. 

Order of execution should not matter


What is the difference between standard For loop and Parallel.For loop ? 

1. Standard for loop executes in a single thread where as Parallel.For loop executes in multiple threads

2.Standard for loop executes in sequential order but Paralllel.For loop will not execute in order. 



Parallel is a static class with static For, ForEach and Invoke methods. 


 public static ParallelLoopResult For(int fromInclusive, int toExclusive, Action<int> body);

NOTE that the first parameter is  Inclusive and  end parameter is Exclusive. 



How do you control the degree of parallelism in Parallel.For loop ? 


By using MaxDegreeOf Parallelism. 


We can pass a ParallelOptions parameter to Parallel.For loop as third parameter. 

In this ParallelOptions object we can set MaxDegreeOfParalllism: 


var options = new ParallelOptions (){ 

MaxDegreeOfParallelism = 2 


Parallel.For( 0, 100 , options, x=> {} );


If MaxDegreeOfParallelism is set to -1, then there is no limit on the number of concurrently running tasks.


How to limit MaxDegreeOfParallelism to use maximum 75% of resources ? 

int NoOfCoresPerProcessor = 2;

new ParallelOptions

{

    MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * NoOfCoresPerProcessor ))

};


ParallelLoopState.Stop and ParallelLoopState.Break methods 

In Break: 

all the previous iterations are completed (index < LowestBreakIteration) 

all the higher index iterations will exit at their convenience

In Stop: 

all iterations will exit at thier convenience


What is the difference between parallelism and concurrency ? 

In concurrency, tasks take turn for execution. So if tasks T1 and T2 

are executing, when T1 executes, T2 waits for its turn and vice versa. 

But in parallelism, both tasks execute at same time. 



How to determine if the parallel loop is complete ? 

By using ParallelLoopResult.IsCompleted flag. 

Console.WriteLine("IsCompleted: {0}", parallelLoopResult.IsCompleted);


Potential pitfalls : 

https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/potential-pitfalls-in-data-and-task-parallelism


===================================================================

Blockchain C# 

https://www.c-sharpcorner.com/article/building-a-blockchain-in-net-core-p2p-network/

Building A Blockchain In .NET Core - P2P Network

Henry He

===================================================================

http://dotnetpattern.com/top-linq-interview-questions

code with mukesh 

C# Corner  sarathlal saseendran

===================================================================

Repository and dapper 

http://www.mukeshkumar.net/articles/web-api/dapper-and-repository-pattern-in-web-api

https://cpratt.co/truly-generic-repository-2/

https://www.c-sharpcorner.com/article/implement-unit-of-work-and-generic-repository-pattern-in-a-web-api-net-core-pro/

https://www.c-sharpcorner.com/article/implement-unit-of-work-and-generic-repository-pattern-in-a-web-api-net-core-pro/

====================================================================

How do put a cap on the maximum size of a file that can be uploaded in a WEB API using multiplart mime type ? 
services.Configure<FormOptions>(options => { // Set the limit to 256 MB options.MultipartBodyLengthLimit = 268435456; });

Saturday, May 14, 2022

EF Error : Unable to translate the given 'GroupBy' pattern. Call 'AsEnumerable' before 'GroupBy' to evaluate it client-side.

 I was trying out code from an article on c# corner  related to angular and web api. 

In one of the methods, there was a code like: 

        public IQueryable<Authors> GetAuthors()

        {

            return _dbContext.ArticleMatrices.GroupBy(author => author.AuthorId)

                  .Select(group =>

                        new Authors

                        {

                            AuthorId = group.FirstOrDefault().AuthorId,

                            Author = group.FirstOrDefault().Author,

                            Count = group.Count()

                        }).

                  .OrderBy(group => group.Author);

        }


This was a GET web api method so I tried calling it from browser. Suddenly I encountered following error : 

Unable to translate the given 'GroupBy' pattern. Call 'AsEnumerable' before 'GroupBy' to evaluate it client-side.


I found that the extension methods GroupBy , Select and OrderBy work on different input types. 

GroupBy works on IEnumerable 

Select works on  IEnumerable

But OrderBy works on IQueryable


GroupBy above gives error because _dbContext.EntityName returns IQueryable and GroupBy expects IEnumerable. 

Select works on IEnumberable so no issue for it. 

But OrderBy expects IQueryable ! 


Changing the above code as following worked: 


        public IQueryable<Authors> GetAuthors()

        {

            return _dbContext.ArticleMatrices.AsEnumerable().GroupBy(author => author.AuthorId)

                  .Select(group =>

                        new Authors

                        {

                            AuthorId = group.FirstOrDefault().AuthorId,

                            Author = group.FirstOrDefault().Author,

                            Count = group.Count()

                        }).AsQueryable()

                  .OrderBy(group => group.Author);

        }

What is application bootstrapping in angular ?

 Bootstrapping is the process of starting application in angular. 

The entry point for an angular application is index.html. 


Index.html loads required javascripts. Then angular loads the main module and components which are by default app.module and app.component. 


Angular booting is a six step process: 

  1. Load index.html
  2. Load Angular, Other Libraries, and App Code
  3. Execute main.ts File
  4. Load App-Level Module
  5. Load App-Level Component
  6. Process Template



https://www.pluralsight.com/guides/bootstrapping-an-application-in-angular

https://angular.io/guide/bootstrapping


Angular NgModule is a component which specifies how different part of the application fit togather.

@NgModule decorator takes  four metadata objects: 


declarations

imports

providers 

bootstrap



Frequently used Angular modules 

BrowserModule

CommonModule  (NgIf and NgFor)

FormsModule

ReactiveFormsModule

RouterModule

HttpClientModule

Note that BrowserModule imports CommonModule and re-exports it.

Sunday, May 8, 2022

Kamil Grzybek

 

https://www.kamilgrzybek.com/

https://www.kamilgrzybek.com/


https://github.com/kgrzybek/modular-monolith-with-ddd




seeing sharply


https://www.blog.jamesmichaelhickey.com/Practical-Coding-Patterns-For-Boss-Developers-Special-Case/

Some good links for Redis

Sitepoint Redis


Redis C# Corner Sarathlal




Difference between Include and ThenInclude 

Difference between Select and SelectMany ==> 

SelectMany flattens the resultset if it contains collections of collections 

Is there any difference if there is no collection of collections in resultset 

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...