Wriju's BLOG

.NET, Cloud and everything

TechEd 2011 India

Thanks everyone. It was pleasure talking to all of you in India TechEd 2011 on “Choosing Right Data Access Methodologies”. It was a jam packed session and a lot of people were standing or sitting on the stage. I loved talking. Huge!!! I have been getting emails to share resources. Let me tell you one… Read more

EF4: What’s in it there in Foreign Key

There are a lot of buzz around the Foreign Key support in ADO.NET Entity Framework v4. Question often comes to our mind that what is so special here? While discussing with my fellow Consultant Vijay, he gave me a nice example. Let me share here, Let’s assume that you have two tables Dept and EmpDept…. Read more

EF4 : Use MergeOption.NoTracking for better query performance

If you are just trying to fetch the data and has no intention to update it. Then you should be using the MergeOption.NoTracking to ensure that the ObjectStateManager does not store the required information for update and delete. Hence your query would be more quick in nature. using (NorthwindEntities ctx = new NorthwindEntities()) {     ctx.Customers.MergeOption… Read more

ADO.NET Entity Framework 4.0: Making it fast through Compiled Query

If we are using similar query frequently, we can increase it’s performance by Compiling it through CompiledQuery. It’s always recommended to use CompiledQuery if you happen to see the query is getting executed many times. Let’s take an example, in Northwind database if you are getting Customer based on City. You may follow the below… Read more

ADO.NET Entity Framework 4.0: Simple N-Tier with Self-Tracking Entities and WCF

ADO.NET Entity Framework 4.0 allows us to easily create N-Tier Application with the help of Self-Tracking Entities. This means now we do not have to worry about merging and checking values in more disconnected scenario. Here is how we can do it in very simple example to start with. Create Model Layer ·         Create a… Read more

ADO.NET Entity Framework 4.0 : POCO – The Code Only Approach

POCO in ADO.NET Entity Framework 4.0 has been discussed in many places. Here I am not going to talk about it. However, I created a small sample to demonstrate the capability of POCO in much more cleaner “code-only” approach. <<Apology for this blog post issue>>. There were some images, due to which it was not… Read more

ADO.NET Entity Framework v2 : ExecuteStoreQuery

There is now an option in ADO.Net Entity Framework v2 for us to execute store query,   IEnumerable<Customer> custs =  ctx.ExecuteStoreQuery<Customer>(“SELECT * FROM Customers”, null);   foreach (var c in custs) {     Console.WriteLine(c.CustomerID);     }   Namoskar!!!  … Read more

ADO.NET Entity Framework : Editing a detached Object

In Layered scenario, you might need to pass an object to another method while updating. Carrying open Context is not good however you may try the below approach by using “CreateEntityKey”. But this will not work if you have configured your edmx with Stored Procedure, reason behind that is static void Main(string[] args) {    … Read more

Data Services (aka Astoria) : CRUD (Select / Insert / Update / Delete )

Creating Astoria is very easy and many of you might have tried that out. What important for us is to work with that data. If you are developing Visual Studio Solution then things are quite obvious as mentioned below, Either you will have Astoria or you will create that service. I am not going in… Read more

LINQ to SQL : Using ChangeSet for Audit Trail

Most of the transactional scenario, you may need to add the transaction to some table for ref. many apps does it for admin perspective.   Problem   You can do it in LINQ to SQL with ChangeSet but the problem is with Inserts. It does not give you the Identity field value until and unless… Read more

ADO.NET Entity Framework vs LINQ to SQL

  I have been getting a continuous request on what we should be using? LINQ to SQL or ADO.NET Entity Framework? I have posted few articles on that, please feel free to visit   Choosing between ADO.NET Entity Framework and LINQ to SQL Choosing between LINQ to SQL and Entity Framework   ADO.NET Entity Framework… Read more

ADO.NET Entity Framework Resources

Compiled Resources http://www.renaissance.co.il/downloads/Entity%20Framework%20Essential%20Resources.pdf   Articles   Next-Generation Data Access: Making the Conceptual Level Real http://msdn.microsoft.com/en-us/library/aa730866(VS.80).aspx   The ADO.NET Entity Framework Overview http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx   ADO.NET Tech Preview: Entity Data Model http://msdn.microsoft.com/en-us/library/aa697428(VS.80).aspx   ADO.NET Entity Framework Overview http://blogs.msdn.com/adonet/archive/2008/03/27/ado-net-entity-framework-performance-comparison.aspx   Channel9 Videos   ADO.NET Entity Framework on Channel 9 Pablo Castro, Mike Pizzo, and Britt Johnston http://blogs.msdn.com/adonet/archive/2006/07/19/671805.aspx  … Read more

Choosing between ADO.NET Entity Framework and LINQ to SQL

As part of my day to job I come across a very common question from the developer community that one should be using LINQ to SQL (L2S) or ADO.NET Entity Framework (EF).   Earlier I have posted a blog containing the features http://blogs.msdn.com/wriju/archive/2009/01/05/choosing-between-linq-to-sql-and-entity-framework.aspx.    To me I feel very excited about EF as it has got… Read more

ADO.NET Data Services (Astoria) Resources

ADO.NET Entity Framework Resources http://msdn.microsoft.com/en-us/library/cc907912.aspx   Overview: ADO.NET Data Services http://msdn.microsoft.com/en-us/library/cc956153.aspx   ADO.NET Data Services Team Blog http://blogs.msdn.com/astoriateam/   Phani Raj’s Blog http://blogs.msdn.com/phaniraj/   Mike’s Podcast ADO.NET Data Services (VS08 Sp1 B1) – Surfacing Data ADO.NET Data Services (VS08 Sp1 B1) – Querying ADO.NET Data Services (VS08 Sp1 B1) – .NET Clients ADO.NET Data Services… Read more

ADO.NET Entity Framework : Working with Stored Procedure

Here we go, I generally get questions from developers that if they will have to scrub the existing powerful stored procedure they have written by investing time and money. The answer to that is “NO”. You must enjoy using it as it has its own power.   So it is very simple in ADO.NET Entity… Read more

ADO.NET Entity Framework : Paging EntitySQL

Paging in EntitySQL is really easy to achieve. You have got two important sub-clauses (or query operators) are available, SKIP and LIMIT.   So your paging EntitySQL query would ideally look like, “SELECT VALUE e FROM NorthwindEntities.Customers AS e ORDER BY e.CompanyName SKIP 10 LIMIT 10 “;   The most important part is that you… Read more

ADO.NET Entity Framework : Using EntityClient and EntitySQL

Using Entity Framework with LINQ is simple and fun stuff. But if you are concerned about the performance and comfortable writing ADO.NET like code then EntityClient is for you. It resides under System.Data.EntityClient namespace. If you are using it you also need to use the EntitySQL (not T-SQL) so the query will be little different…. Read more

ADO.NET and Data Articles by John Papa

Many of you might be following John Papa’s article on Data and related topics. Myself have came across many of his and are still following. I would like to share a list of articles by him published in MSDN Magazine and available online for you. Data Points: Designing an Entity Data Model With the Entity… Read more

ADO.NET Data Services Resources

Help yourself by exploring below resources on ADO.NET Data Services (aka "Project Astoria"). Data Platform Developer Center – Data Services page Data services conceptual documentation on MSDN Data services API reference documentation on MSDN Data services team blog Data services online forum (a place to ask us your data services related questions) Whitepaper: Using ADO.NET… Read more

LINQ to Entity : Supported and Unsupported Methods

There is a correction for this Post, so do I have changed the title. Thanks to Chris Love who pointed me the faults with earlier post, I got few question on some of the popular paging methods of LINQ which does not work on LINQ to Entity. This is by design and quite logical. In… Read more

ADO.NET Entity: Insert Update and Delete with Relationship

Few days back I had written an article on Insert/Update/Delete for simple standalone tables at ADO.NET Entity: Insert Update and Delete. Now after that many of you had requested me to put article on how it works with relationship.   Here I will use a database created by me. There will be two tables connected… Read more

ADO.NET Entity: Insert Update and Delete

For small blogs, it requires more references and explanation, which sometimes are redundant. So I thought of writing single blog which is combination of topics more or less related to one thing.   I am exploring ADO.NET Entity Framework and have been trying things out there. Here I am planning to demonstrate how to do… Read more

LINQ to SQL vs. ADO.NET – A Comparison

ADO.NET is our contemporary data access component and now we have written many applications. Now there has been a lot of talk on LINQ to SQL. So we are little skeptical about this component and trying to find some relation between existing ADO.NET technology.   Purpose of this post is to give some quick brief… Read more

LINQ to Entity : Querying data using ADO.NET Entity Framework

ADO.NET Entity Framework have evolved since we have released it first time. Now with the Visual Studio 2008 if you install the .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 you will get the fully functional version of ADO.NET Entity Framework. This is post Beta 3 release. To create a .edmx file you have… Read more

ADO.NET : OleDbCommand Parameterized Query Sequence Rule

While working with MS Access database with OleDbCommand you might have faced issue that your parameterized update statement is not working. The most frustrating part is that it also does not throw any runtime error. So ideally you paralyzedJ.   Golden rule is that you need to maintain the exact sequence of parameters you have… Read more


Here I am going to compare the two technologies and point some missing areas.   Let us use the Northwind database and get the list of Customers from city London. The ADO.NET approach would be,   static void Main(string[] args) {     string sConn = @”ConnectionString”;     using (SqlConnection conn = new SqlConnection(sConn))     {… Read more

ADO.NET Entity Framework 3.5 Beta 3 Released today

Beta 3 of the ADO.NET Entity Framework, and a preview of ASP.NET 3.5 Extensions. Designed to make it even easier for developers to build data-centric applications and services regardless of the underlying data source, the ADO.NET Entity Framework is already gaining significant support from multiple database vendors and third-party providers, including Core Lab, Data Direct… Read more

ADO.NET 2.0 : Fine tune your DataSet Performance

ADO.NET 2.0 offers us a unique feature through which we can make a real lightweight DataSet. This is very important and much neglected development practice to overlook the performance part. So when you have huge data and you are getting multiple hit this small tune may help you a lot.   Assume I am working… Read more

LINQ to SQL Windows Form Binding Data Step by Step

LINQ to SQL designer in Visual Studio allows us to create mapped class using the drag and drop feature from Server Explorer. Now that is business object which ideally you could use as your datasource and from Visual Studio 2008. So let us have this step by step, Open your Visual Studio 2008 and create… Read more

MSDN Magazine : Data Point Articles

Data Points: ADO.NET Entity Framework Overview Data Points: Contrasting the ADO.NET DataReader and DataSet by John Papa Data Points: Data Bound Applications with ADO.NET and Custom Objects by John Papa ADO.NET: Tackle Data Concurrency Exceptions Using the DataSet Object by David Burgett Data Points: DataSet and DataTable in ADO.NET 2.0 by John Papa Data Access:… Read more

LINQ to SQL support inserting data through object.

LINQ to SQL support inserting data through object.   using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Linq;   namespace Linq2Sql_demo_doc {     /// <summary>     /// Class to represent the SQL Server table     /// Emp     /// Id int     /// Name varchar(50)     /// </summary>    ///     [Table(Name=“Emp”)]     public class… Read more

LINQ to SQL : Executing DML SQL Query

INSERT/DELETE/UPDATE can be performed in LINQ to SQL through normal T-SQL DML queries,   static void Main(string[] args) {     NorthwindDBDataContext db = new NorthwindDBDataContext();   var query = db.ExecuteCommand(“YOUR DML Query”, “Your    Parameter”);       ObjectDumper.Write(query); }   Are you feeling comfortable? Hold on, please try to avoid this as you have better object… Read more

LINQ to SQL : Executing SQL Query

Yes, you can run normal SQL queries in LINQ to SQL. Sample looks like (but not recommended as you do not have statement completion and validation)   static void Main(string[] args) {     NorthwindDBDataContext db = new NorthwindDBDataContext();       var query = db.ExecuteQuery<Customer>(“SELECT * FROM Customers”, “”);       ObjectDumper.Write(query); }   One of… Read more

ADO.NET Entity Framework June 2007 CTP is available

Overview This CTP contains updates to the ADO.NET Entity Framework since the Visual Studio Codename “Orcas” Beta 1 release, including changes in Object Services, Query, Entity Client, and the Entity Data Model Wizard in Visual Studio. Some of the new features include IPOCO, detaching from long-running ObjectContext instances, multiple entity sets per type, support for… Read more

Astoria Next Generation of Data Access for Web

Project codename “Astoria” is to enable enable applications to expose data as a data service that can be consumed by web clients within a corporate network and across the internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the… Read more

Orcas Beta 1 ADO.NET vNext First Look

What is ADO.NET vNext or Entity Framework? It has been a long journey for the application development and data access. Starting from DLib,… DAO, ADO, ADO.NET. Now the world is for ADO.NET vNext or Entity Framework model. This is to increase the level of abstraction and avoid the change mismatch. In Orcas the designer is… Read more

LINQ to SQL with real life ASP.NET Data Domain

We have talked a lot about LINQ and its power. One of the main reasons behind the LINQ design goal was to enable the unified query like syntax for any kind of structured data.   There is hardly any ASP.NET application which does not deal with data. We can create layered ASP.NET Application using the… Read more

LINQ: Custom Object Query

Applies To: .NET Framework 3.0, LINQ   Hello all, I have already discussed about the LINQ model architecture and the query process for .NET object in my previous posts. But how about the object written by you? Most of the time we write our own object and return the collection. LINQ is applicable for any… Read more

LINQ: The Philosophy

Applies To: .NET Framework 3.0, LINQ   LINQ (Language INtegrated Query) it is unified programming model for any kind of data in a data-centric application. Be it Database, XML or Object, this uses same query language throughout. This query language or set operation is integrated in the .NET ecosystem as natural expression language. This concept… Read more