Pages

Sunday, 28 July 2013

How to use LINQPad

 

Introduction

Querying is merely a special case of using LINQPad. More generally, LINQPad is a C#/VB/F# scratchpad that instantly executes any expression, statement block or program with rich output formatting and a wealth of features that "just work". Put an end to those hundreds of Visual Studio Console projects cluttering your source folder and join the revolution of LINQPad scripters, testers, and incremental developers. Reference your own assemblies and NuGet packages. Script in your favorite .NET language with optional autocompletion and the entire .NET Framework at your fingertips. Experience the magic of dynamic development and instant feedback in the ultimate programmer's playground!

Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

You can download LINQPad from here http://www.linqpad.net/.

The steps we follow how to use LINQPad

Open the LINQPad and add new connection

clip_image002

Click on Add Connection then open the new connection wizard select Default (LINQ toSQL) and click the Next Button.

clip_image004

Enter the Server Name. Here we can mention the authentication type also

clip_image005

Specify New or existing Database

clip_image006

Select the Database name here

clip_image007

After that we can test the Connections

clip_image008

Now it’s showing all the database tables here clip_image010

We can select the different Languages from here

clip_image012

Simple Select query and execute

clip_image014

Now we need to select the C# Statement(S)

clip_image016

Write a simple select query and for execute the query we need to use the .Dump() command.

clip_image018

After that we can run the query

clip_image020

Right click on the table we have get some more inbuilt query options

clip_image022

The Samples tab has more examples for efficient LINQ queries

clip_image024

Reference

http://www.linqpad.net/.

Wednesday, 10 July 2013

Create My First Entity Data Model(EDM)

 

This topic describes how to create a new .edmx file by using the Entity Data Model Wizard. An .edmx file contains the the conceptual model, as well as a storage model and the mappings between them. The procedures in this topic describe how to generate an .edmx file that is based on an existing database and how to generate an empty .edmx file.

Create new project in visual studio

clip_image002

Select ASP.NET Empty Web Application

(We can create Class library or console application)

clip_image004

Here Add new item in this project

clip_image006

Here we need to Add ADO.NET Entity Data Model

clip_image008

Now its open the Entity Data Model Wizard , we need to select option like Generate from database.

To create an empty .edmx file select the option Empty model.clip_image010

Here we need to create New Connection

clip_image011

Select the option Microsoft SQL Server

clip_image012

Enter the Server name here

clip_image014

Select he Database name from the dropdown list.

clip_image016

Click on the Test Connection button ,it will show the Test Connection success message

clip_image018

Now the new connection created and we can see the entity connection string.

clip_image019

Here we have the options to select Tables,Views,Stored Procedures and Functions from that database.

clip_image020

Now our first .edmx file is generated

clip_image022

In our solution of the project we can see .edmx file which generated automatically

clip_image023

Reference

http://msdn.microsoft.com/en-us/library/cc716703(v=vs.103).aspx

Summary

In this article we learned the basic steps to create the EDM