Building Single Page App Using ASP.NET Core with Entity Framework Core and AngularJS

Hi Friends,

In this particular post, I thought to unveil my book on latest Microsoft ASP.NET Core stack in conjunction with Angular. This is basically hand-book for all those people who like to build Single Page App, right from the scratch meeting all the industry standards.


Continue reading “Building Single Page App Using ASP.NET Core with Entity Framework Core and AngularJS” »

7,350 total views, no views today

Getting Started with LINQ – Part 4

Hi Friends,

In today’s section we’ll delve further and see more of LINQ. Let us get started with Take and skip operations.

This will produce me the following output.


Below is the same example while querying db.


Now, let us see select many example.


Cross product example.


Cross product Join example:-


Database cross Join:-



Filtered Association:-


Joining the parent:-


Outer Join – 1st:-


Outer Join – 2nd


Thanks for joining me.

Rahul Sahay
Happy Coding

1,686 total views, 1 views today

Getting Started with LINQ – Part 3

Hi Friends,

In this section, we are going to delve further. We’ll first start with filtering process. Below is the snippet for the simple filtering process.

This will produce the following result.


Now, let us look at complex style of filtering with multiple where clauses.


Now, let us see the scenario where in we want to skip every 2nd item like shown below.

This will produce the below output.


Let us now query against database. Here, i am reviewing against my movie review database. Here, i am referring Movies table as shown below.


Now, let us consider a scenario where you want to query what IN and NOT-IN scenario as shown below.


Thanks for joining me. We’ll continue same thing in another session. Till then stay tuned and happy coding.

Rahul Sahay
Happy Coding

1,711 total views, no views today

Getting Started with LINQ – Part 2

Hi Friends,

In this section, we’ll proceed further and look different projection strategies. So, the 1st case which i am using here is the Object Initializers. With C# Object Initializers, we can project the same into more complex types. For example, suppose, as a first step in a query, we want to strip vowels from a list of names while still keeping the original versions alongside, for the benefit of subsequent queries. Therefore, we can write as shown below


However, Anonymous Types allow you to structure your intermediate results without writing special classes. So, here we can remove TempProjectionItem as shown below in the example.


The let keyword introduces a new variable alongside the range variable. With let, we can write a query extracting strings whose length, excluding vowels, exceeds two characters, as follows:


The compiler resolves a let clause by projecting into a temporary anonymous type that contains both the range variable and the new expression variable. Thanks for joining me. In the next section, we’ll delve further and check other pieces as well. Till then stay tuned and happy coding

Rahul Sahay
Happy Coding

1,897 total views, no views today

Getting Started with LINQ

Hi Friends,

In today’s discussion, we’ll look into LINQ operations. LINQ or Language Integrated Query is a set of language and framework features for constructing type safe queries over local collections or remote data sources. It was introduced in C# 3.0 and framework 3.5.

The basic units of data in LINQ are sequence of elements which actually implements IEnumerable. In the below example,
employees is sequence and “John”,”Dave”,”Black”,”Jack” are elements.

string[] employees = {"John","Dave","Black","Jack"};

A query operator is the one which transforms the sequence. A typical query operator accepts a sequence and emits a transformed output sequence. For, IEnumerable case, we have around 40 query operators. They are also known standard operators.

Let us get started with few simple queries.

Note:- I am using LINQPAD to run these queries. Hence, final statement dump is specific to it. It’s basically used to show the output.

string[] employees = {"John","Dave","Black","Jack","Rahul"};

IEnumerable<string> filtered_emp = employees.Where(n=>n.Length>4);

filtered_emp.Dump("Simple usage of Query");


Since, standard query operators are implemented as static methods, we can directly call Where on employees. Most query operators accept lambda expressions as an argument like here we have n=>n.Length>4.

Now, Let’s look at complex query

string[] employees = {"John","Dave","Black","Jack","Rahul"};

IEnumerable<string> query = employees.Where(n=>n.Contains("a"))

query.Dump("Simple usage of Query");


here, what it is doing; taking the input, extracts all the strings containing letter a then sorts them by length and then converts the same in lower case. Here, the variable n is privately scoped to each lambda expressions. Here, OrderBy and Select are standard query Operators.

Now, let’s look at Range Variable. The Identifier immediately following the from keyword syntax is called the Range variable. For instance, in below example

from n in new[] { "John","Dave","Black","Jack","Rahul" }
where n.Contains ("a")
select n


Chaining of query operator is very efficient in many cases like shown below.

string[] names = { "John","Dave","Black","Jack","Rahul" };

IEnumerable<string> query = names
	.Where   (n => n.Contains ("a"))
	.OrderBy (n => n.Length)
	.Select  (n => n.ToUpper());

// same query rewritten progressively:

IEnumerable<string> filtered   = names.Where      (n => n.Contains ("a"));
IEnumerable<string> sorted     = filtered.OrderBy (n => n.Length);
IEnumerable<string> finalone = sorted.Select    (n => n.ToUpper());

filtered.Dump   ("Filtered");
sorted.Dump     ("Sorted");
finalone.Dump ("FinalQuery");


So, as you can see in the above example same final query is achieved in the first expression and again same thing achieved differently by writing the same progressively. Similarly, sometimes we need to keep the natural ordering of numbers as it is.

int[] numbers  = { 10, 9, 8, 7, 6 };

numbers.Take (3)  .Dump ("Take(3) returns the first three numbers in the sequence");
numbers.Skip (3)  .Dump ("Skip(3) returns all but the first three numbers in the sequence");
numbers.Reverse() .Dump ("Reverse does exactly as it says");


Now, in the end there are other important operators which are equally important.

int[] numbers = { 10, 9, 8, 7, 6 };

// Element operators:

numbers.First().Dump ("First");
numbers.Last().Dump ("Last");

numbers.ElementAt (1).Dump ("Second number");
numbers.OrderBy (n => n).First().Dump ("Lowest number");
numbers.OrderBy (n => n).Skip(1).First().Dump ("Second lowest number");

// Aggregation operators:

numbers.Count().Dump ("Count");
numbers.Min().Dump ("Min");

// Quantifiers:

numbers.Contains (9).Dump ("Contains (9)");
numbers.Any().Dump ("Any");
numbers.Any (n => n % 2 != 0).Dump ("Has an odd numbered element");

// Set based operators:

int[] seq1 = { 1, 2, 3 };
int[] seq2 = { 3, 4, 5 };
seq1.Concat (seq2).Dump ("Concat");
seq1.Union (seq2).Dump ("Union");



Thanks for Joining me.

Rahul Sahay
Happy Coding

2,580 total views, 1 views today


Hi Friends,

In this section, I’ll introduce you with one of my favorite tools i.e. Linqpad. you can download the same from This is extensive tool for .NET programmers. LINQPAD is The .NET Programmer’s Playground. Here, you can do bunch of stuffs like executing LINQ query against SQL, Azure, XML, any object or against any other database. You can add your SQL connection like shown below.



As you can see in the below screen shot, I have simply pulled the movies from my movie review db.


Then, If i have to see the relationship between the tables, then i can simply go ahead and click on the highlighted link shown in the table above. Like in this case, when i clicked on “MovieReviews”, it produced the below result.


Behind the scenes it also generated the actual SQL statement as shown below in the screen shot.


You can also execute SQL statement as shown below in the screen shot. only thing you need to change here is the language from the dropdown.


Thanks for joining me.

Rahul Sahay
Happy Coding

3,514 total views, 1 views today

LINQ Extensions

Hi Friends,

In today’s section we’ll see how to use extension methods to achieve the same thing which can be achieved via Comprehension LINQ query.

Below is the code to fetch the same thing via two ways.

I have also created Movies Repository, just to segregate my stuffs here. So, GetMovies() is just fetching all the movies from the repository.

so, now at this point you might be thinking that what i should be using Extension Method or comprehension query. Basically, its a personal choice. If users feel handy with comprehension query, they write comprehension query otherwise extension methods. However, my point is extension methods using lambda expressions generally offer more flexibility over comprehension queries and the general reason for that not all LINQ keywords are exposed to comprehension queries. So, when you are writing extension methods then in that case select operator is optional.

Now, lets see let keyword. let keyword is really important in LINQ queries for persisting some value for later execution like shown below


here, in the movies repository i have modified the name just to execute the query, but that ok that was just done to prove the point. Now, there is one more keyword which is used for grouping or i would say for additional filtering like the example shown below.


below in the snippet i have used group operator to partition my results as shown below.


I have also modified Movie class and Movie Repository

Now, lets suppose you would like to print some additional information like for a particular Genre Id, total count and its collection. So, to do that i’ll extend the query with anonymous syntax as shown below.


Now, lets look at Join query.

for this i have also created one new MovieReview Repo as shown below in the snippet.

so, when i run the same, i will get the below result


I can also go ahead and use LINQ composition like shown below.

For this custom type, i have created the same in my movie repository as shown below in the snippet

Now, when i run the same, it will produce me the below output.


Now, this kind of query is very useful as it increases reusability of the code.

Thanks for joining me.

Happy Coding

3,228 total views, 1 views today


Hello Friends,

In this section we are going to talk about LINQ TO SQL. Now, Linq to SQL is a simple Object Relationship Mapper(ORM) which means there is equivalent mapping of your class atrributes with Sql server table columns. This works fine with variety of SQL Server technologies. Here, basically our LINQ queries get translated into SQL queries and do the execution down the layer and fetch or commit the data. Then, what i have done is i have added LINQ TO SQL below in my visual studio to visualize my tables as shown below in the diagrams.




Here, we can also see the relationship between Movie and MovieReviews table by clicking on the arrow and checking the properties there. So, here MovieReviews are associated with Movie via foreign key as shown below in the screen shot.


So, with LINQ to SQL, we have also created the data context with which we are going to interact with SQL.


Now, when i start writing my query on the datacontext, it started giving me properties against which i am going to write my query as shown below in the screen shot. Now, this is the significance of ORM. By default, ORM pluralizes your table, but you can override these properties, but thats ok; this is not in the scope of this topic.



so, here the query is fetching best movies based on the average of rating in descending order.


Now, if i hover on the LINQ expression in debugging window, then you can see that LINQ expression got converted into SQL query and this is how it is going to pick the data from db.


and if i simply copy the expression and put the same in the notepad, i can see that it has created the SQL expression as shown below.

one point to note here that LINQ TO SQL is again lazy loader means, it won’t execute the query in the database until it is invoked from a specific call. In this case it is from foreach() statement. This was how LINQ TO SQL works in a nutshell. Thanks for joining me.

Rahul Sahay,
Happy Coding

2,678 total views, 2 views today

Getting started with LINQ

Hi Friends,

In today’s section, we are going to talk about LINQ and its capabilities. Now, LINQ is something which gives you out of the box querying facility in statically typed language itself means in C# itself. Let’s see some of the examples in action. Below, I have created one simple movie class with few properties in it.

however, when i am writing the query in the main program, you can see that intellisense is giving me all the properties which i have created above.


when i execute the same, it prints the below value.


However, there are around 50 standard operators provided by microsoft to query the things. You can check each implementation on MSDN as well. Also, LINQ is designed in such a way that it supports all kind of extensibility like you can write LINQ to LDAP, Amazon, Flicker or you can write your own custom operators as well.

However, we can also go ahead and use LINQ to query objects like shown in the below snippet

so, it produced me the Movie type as public type.


Deferred Execution is again one of the most crucial part of LINQ operations means we can have the query defined, but until we invoke it that query part is not going to be executed. Consider the below example where in i am adding a new movie to list and then invoking the query from the foreach() operation. So, in the final result it will print me the expected value as shown below.


I can also use LINQ to query XML like shown below. So, here i have constructed one xdocument on the fly of processes and querying the same via LINQ.


then, i can see the result in the debugging visualizer as shown below.


Now, since the document is constructed i can go ahead query the document as well as shown below in the snippet.


This was the brief introduction of using LINQ with variety of instances. we’ll delve further inside this in the coming sections. Till then stay tuned and Happy Coding.

Rahul Sahay
Happy Coding

2,064 total views, no views today

Hands-On With ASP.NET MVC – eBook Copy- Pre Launch Offer

For Indian readers, I have setup a different store. Please visit the below mentioned to place your order within india.

Store URL:-

Price comparison is done keeping “” as benchmark. You can buy same book at discounted price from my store….This is Pre Launch Offer. Book is getting released world wide in another 10-15 days at leading book store. But, you can book your ebook copy now at discounted price from my store…..Upon Ordering you will receive 1st sample chapter now, and complete book in 10-15 days on your email, when the book is officially released….Other formats will also be available soon….

1,391 total views, no views today