How to create relationships between entities in the Entity Framework Code First Approach

The Entity Framework Code First approach allows us to create a model as a plain class and then the database gets created from the domain model or entity class. In the Code First approach, the database gets created from the classes. Some advantages of the Entity Framework Code First approach include (as stated in Scott … Continue reading How to create relationships between entities in the Entity Framework Code First Approach

How to view the generated SQL Query of LINQ

Have you ever thought of viewing generated SQL query of LINQ you write? You may need the generated query for the debugging and the logging purposes. In this post let us see how to print the generated SQL query on the console. Let us consider you have written LINQ as follows: You can print the … Continue reading How to view the generated SQL Query of LINQ

What is difference between First and FirstOrDefault in LINQ?

Last week I were presenting LINQ to group of almost 100 audience. While writing query a question raised that what is difference between First and FirstOrDefault . At that time I was not very sure about answer so I asked audience to help me. One from audience answered this question. So credit of this blog … Continue reading What is difference between First and FirstOrDefault in LINQ?

LINQ to XML in a Nutshell

Data may exist in much form. You may have data in relational tables residing on a relational database or portable data in form of XML. Since data exist in many forms, obviously there are many ways to manipulate or access them. One of the most popular ways of sharing data is as XML. Considering prominent … Continue reading LINQ to XML in a Nutshell

ASP.Net GridView with LinqDataSource

In this post I will walkthrough on using ASP.Net Gridview with LinqDatasource. You can bind a GridView with LinqDataSource and would able to Edit Delete View data without writing a single line of code. To see how it works , follow the steps below; Step1 Crate a ASP.Net Web Application. Step 2 Right click and … Continue reading ASP.Net GridView with LinqDataSource

Executing SQL Query using LINQ to SQL

In this post, I will discuss how we can execute a SQL Query directly from LINQ. Explanation To execute SQL query there is a method in DataContext class called ExecuteQuery ExecuteQuery takes two input parameter 1. SQL Query as string 2. Parameters used in SQL query And it returns an IEnumerable. Example Below code will … Continue reading Executing SQL Query using LINQ to SQL