<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Zeeshan Hirani</title><subtitle type="html" /><id>http://weblogs.asp.net/zeeshanhirani/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/zeeshanhirani/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2010-06-14T12:27:49Z</updated><entry><title>Configuring Existing DataBase with Many-to-Many using Code First</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/12/08/configuring-existing-database-with-many-to-many-using-code-first.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/12/08/configuring-existing-database-with-many-to-many-using-code-first.aspx</id><published>2010-12-09T02:33:45Z</published><updated>2010-12-09T02:33:45Z</updated><content type="html">With CTP5 of Code First, you can easily map existing database schema to classes in your project.&amp;#160; It allows you to configure what class and property gets mapped to what table and column in the database. Code First gives you two options to configure the mapping. You can either use DataAnnotation such as attributes or use the fluent api to explicitly control every single detail about the mapping. In the existing database schema, I had a many-to-many table and I was wondering what would be the...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/12/08/configuring-existing-database-with-many-to-many-using-code-first.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7658456" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Builder Methods to create dynamic esql queries</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/12/01/builder-methods-to-create-dynamic-esql-queries.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/12/01/builder-methods-to-create-dynamic-esql-queries.aspx</id><published>2010-12-01T05:16:55Z</published><updated>2010-12-01T05:16:55Z</updated><content type="html">In the current project, I am working on,&amp;#160; I make use of esql heavily. One of the reason is because I am still using EF v1 which has limited support for linq queries. The second reason is, if you have dynamic queries which are build on what user selects from the search criteria, esql makes the job much easier. This is why Entity Framework supports the concepts of using builder methods. Builder methods allow you write sections of code using esql like a dynamic where clause, orderby clause or returning...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/12/01/builder-methods-to-create-dynamic-esql-queries.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7653452" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Filtering and Ordering Include</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/11/12/filtering-and-ordering-include.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/11/12/filtering-and-ordering-include.aspx</id><published>2010-11-13T03:25:16Z</published><updated>2010-11-13T03:25:16Z</updated><content type="html">Lot of times in your application, you have a requirement to eagerly load related collection but you want to load the collection partially and also have the data sorted when before it is materialized at the client layer. Currently in EF, there is no direct way to filter and sort and Include but there is a workaround. In this blog post, I will show you how you can use anonymous type to paritally load a collection in the correct order you desire. Suppose you have a model consisting of Customers and...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/11/12/filtering-and-ordering-include.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7641798" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Binding Stored Procedure Result from Entity Framework to ObjectDataSource Control</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/11/02/binding-stored-procedure-result-from-entity-framework-to-objectdatasource-control.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/11/02/binding-stored-procedure-result-from-entity-framework-to-objectdatasource-control.aspx</id><published>2010-11-03T03:11:23Z</published><updated>2010-11-03T03:11:23Z</updated><content type="html">Not too long ago someone asked me how can they bind data returned from stored procedure to a gridview control. There are several ways to achieve that. You can either use EntityDataSource or ObjectDataSource Control. I find it easier to use ObjectDataSource control because it allows me to encapsulate logic inside my classes. The basic steps are as follows 1. Bring the Stored Procedure into the storage model. 2. Import the stored procedure into conceptual model. This will result in a method getting...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/11/02/binding-stored-procedure-result-from-entity-framework-to-objectdatasource-control.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7635984" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Using GetObjectByKey to short circuit database call</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/21/using-getobjectbykey-to-short-circuit-database-call.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/10/21/using-getobjectbykey-to-short-circuit-database-call.aspx</id><published>2010-10-21T22:16:53Z</published><updated>2010-10-21T22:16:53Z</updated><content type="html">There are several ways to query for a single entity using Linq such as First or Single. For instance in the code below we are retrieving customer based on CustomerID If you execute the above code 5 times with the same object context, EF will execute the same query 5 times. In Linq to sql, once you fetch an entity once, next time you retrieve it using First Or Single, it will check the context first and if it finds the entity in the context it will never hit the database. This feature is useful in...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/21/using-getobjectbykey-to-short-circuit-database-call.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7630357" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Inserting,Updating and Deleting entity using Stored Procedures</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/14/inserting-updating-and-deleting-entity-using-stored-procedures.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/10/14/inserting-updating-and-deleting-entity-using-stored-procedures.aspx</id><published>2010-10-14T06:07:27Z</published><updated>2010-10-14T06:07:27Z</updated><content type="html">If you have used entity framework with stored procedure, you would realize it has a great designer and runtime support. Yes there are few gotchas and loose ends that needs to be fixed but it does the job 99% of the time. In this blog, I will show you how to use stored procedures to perform crud operations on a single entity. Suppose we have a model containing Article entity as shown below. &amp;#160; You can by default use the dynamic insert,update and delete statements EF generates to insert the article...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/14/inserting-updating-and-deleting-entity-using-stored-procedures.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7626633" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Upgrading Independent Association to Foreign Key Association</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/13/upgrading-independent-association-to-foreign-key-association.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/10/13/upgrading-independent-association-to-foreign-key-association.aspx</id><published>2010-10-13T05:15:18Z</published><updated>2010-10-13T05:15:18Z</updated><content type="html">In EF when you want to define a relationship between two entities, you typically use an association. An association can be many-to-many, 1.. 0..1, many-to-1 etc. Typically you would have tables in the database which are related to each other using foreign key constraints. When you import those tables in Entity Framework, EF would create an association. In v1 of EF, there is only 1 type of association called Independent Association. Independent association is an association which is tracked separately...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/13/upgrading-independent-association-to-foreign-key-association.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7626232" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Thanks EF4. Now i can put my orderby clause anywhere</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/10/thanks-ef4-now-i-can-put-my-orderby-clause-anywhere.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/10/10/thanks-ef4-now-i-can-put-my-orderby-clause-anywhere.aspx</id><published>2010-10-10T20:28:39Z</published><updated>2010-10-10T20:28:39Z</updated><content type="html">Well most folks wouldn’t have a clue as to what the title of my posting says. This is a problem that stems from EF v1&amp;#160; but is now solved for the most part. in EF4.0. In version 1 of EF, it was recommended that you put your order by operation as the last operation in the query. If you do not put order by as the last operation in the query query, order by would be ignored in some cases. In the code below we are returning products sorted by their unit price. Notice in our query, order by is not...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/10/thanks-ef4-now-i-can-put-my-orderby-clause-anywhere.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7625582" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Watch out for StartsWith when upgrading from .net 3.5 to 4.0</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/06/watch-out-for-startswith-when-upgrading-from-net-3-5-to-4-0.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/10/06/watch-out-for-startswith-when-upgrading-from-net-3-5-to-4-0.aspx</id><published>2010-10-07T03:51:16Z</published><updated>2010-10-07T03:51:16Z</updated><content type="html">Currently I am working on .net 3.5 project so i am having to live with Entity Framework. v1. Anyways i was working on a linq query that was making use of StartsWith operator. For some reason based on which page you are coming from the value passed in to the StartWith was sometimes empty. To be more clear let’s look at a sample code to understand how my scenario looked like. When you run the above code, you get 0 records back. If you look at the sql generated for the above query, it uses CharIndex...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/10/06/watch-out-for-startswith-when-upgrading-from-net-3-5-to-4-0.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7624644" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Which one is faster SingleOrDefault or FirstOrDefault</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/09/20/which-one-is-faster-singleordefault-or-firstordefault.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/09/20/which-one-is-faster-singleordefault-or-firstordefault.aspx</id><published>2010-09-20T18:32:24Z</published><updated>2010-09-20T18:32:24Z</updated><content type="html">Generally, I don't see too much performance problem whether you use Single Or First. However if you have a table with lots of columns like 300 you might notice slight improvement if you use FirstOrDefault. Before we go deeper into the performance difference let’s understand how they are semantically different. When you use FirstOrDefault, you will get the first item that matches a given criteria. When you use SingleOrDefault, you are saying that there can be only one value that matches the criteria...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/09/20/which-one-is-faster-singleordefault-or-firstordefault.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7617198" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Lazy Loading Related Properties</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/08/06/lazy-loading-related-properties-on-poco-objects.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/08/06/lazy-loading-related-properties-on-poco-objects.aspx</id><published>2010-08-06T04:37:06Z</published><updated>2010-08-06T04:37:06Z</updated><content type="html">Lot of times in our application we do not perform eager loading on related entities because we don’t need to display them on the UI unless some action occurs. So we fetch those entities lazily only when we need them. However have you ever felt the need to lazily fetch several related entities? Suppose we have a model consisting officers who gave tickets to Drivers as shown below. &amp;#160; Let’s say on the user interface we are displaying Officer information and based on some action on the user interface...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/08/06/lazy-loading-related-properties-on-poco-objects.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7579659" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Removing entity from a Related Collection</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/23/removing-entity-from-a-related-collection.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/07/23/removing-entity-from-a-related-collection.aspx</id><published>2010-07-23T16:13:46Z</published><updated>2010-07-23T16:13:46Z</updated><content type="html">I have seen this misunderstanding starting to popup more often on how to delete an entity from a related collection. Suppose we have the following entity data model where a Person has many Phones identified by 1-to-many association as shown. Problem: You have an existing Phone entity that you want to remove from the customer’s Phone collection So let’s see how someone just walking into EF does it and assumes that code should works. In the above code, I am creating a new customer and phone entity...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/23/removing-entity-from-a-related-collection.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7572558" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Setting Entity Key for a view</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/06/setting-entity-key-for-a-view.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/07/06/setting-entity-key-for-a-view.aspx</id><published>2010-07-06T15:14:55Z</published><updated>2010-07-06T15:14:55Z</updated><content type="html">When you import a database view using Entity Data Model wizard,you will get an entity that has the same number of columns and data type as the view does.Suppose I have the following view in my database. When I import the view I get the following entity on my model. If you look at the above entity carefully, you would notice EF has marked CustomerId,FirstName,LastName and FullName as the entity key. The entity key EF determines is not random. EF marks all the non null columns as entity key. There...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/06/setting-entity-key-for-a-view.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7555683" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Search for an entity in your Entity Data Model</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/05/search-for-an-entity-in-your-entity-data-model.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/07/05/search-for-an-entity-in-your-entity-data-model.aspx</id><published>2010-07-05T23:07:30Z</published><updated>2010-07-05T23:07:30Z</updated><content type="html">Last week i discovered a feature of Entity Data Model which i have not seen extensively being promoted. I accidentally run into it because of the size of my model. If you have a large model and want to search for an entity, it becomes tedious to zoom in and out and scroll up and down to find your entity. In Entity Framework 4, on the model browser there is a new search option that allows you to search for any artifact on your model, whether it be a property, association, column, entity. Below are...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/07/05/search-for-an-entity-in-your-entity-data-model.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7555120" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry><entry><title>Watch out for let operator in linq to entities</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/zeeshanhirani/archive/2010/06/14/watch-out-for-let-operator-in-linq-to-entities.aspx" /><id>http://weblogs.asp.net/zeeshanhirani/archive/2010/06/14/watch-out-for-let-operator-in-linq-to-entities.aspx</id><published>2010-06-14T16:27:49Z</published><updated>2010-06-14T16:27:49Z</updated><content type="html">LINQ has a really cool operator call Let that lets you declare variables inside the query. The benefit i find in using let is, it makes my query much easier to read because using Let keyword i can create a variable and assign it a calculated value. Then later in my query i can test my value against that variable. In LINQ to entities if you are using let keyword, you want to be aware of how the sql is generated. There are cases where let keyword introduces extra or repetitive joins that are un-needed...(&lt;a href="http://weblogs.asp.net/zeeshanhirani/archive/2010/06/14/watch-out-for-let-operator-in-linq-to-entities.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7530261" width="1" height="1"&gt;</content><author><name>zhirani</name><uri>http://weblogs.asp.net/members/zhirani.aspx</uri></author></entry></feed>