<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">All About Data</title><subtitle type="html" /><id>http://blogs.msdn.com/bindeshv/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/bindeshv/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-03-22T06:51:41Z</updated><entry><title>Displaying WCF Data Service data in local reports</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2009/11/21/displaying-wcf-data-service-data-in-local-reports.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2009/11/21/displaying-wcf-data-service-data-in-local-reports.aspx</id><published>2009-11-21T06:30:42Z</published><updated>2009-11-21T06:30:42Z</updated><content type="html">&lt;p&gt;&lt;font size="2" face="ver"&gt;Its been sometime that I have blogged. I recently got asked by one of my peers on how to display the data from DataService on a local report and how to pass a parameter . &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="ver"&gt;Its relatively easy to do this , the steps would be &lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font size="2" face="ver"&gt;Make a connection to the DataService using Data Service client API &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="ver"&gt;Get the Data as a collection , my favorite List&amp;lt;T&amp;gt; :) &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="ver"&gt;Add it to the ReportDataSource and bind it to the LocalReport&lt;/font&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font size="2" face="ver"&gt;However, regarding the parameter passing , we know that if we add a parameter to the local report it does not prompt for the user and the developer is responsible for getting the value. Also you need to decide whether you need to get the entire data on the client and then do a filter on it or if&amp;#160; you want to get the filtered data from the server based on the parameter selected from the client. I took the former approach and get the entire data(considering the small amount of data that I have ). Here is how &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I am assuming that you already have a neat WCF Data Service defined and ready to take the requests, in this case at &lt;a title="http://localhost:54560/MyDataService/NorthwindService.svc/" href="http://localhost:54560/MyDataService/NorthwindService.svc/"&gt;http://localhost:54560/MyDataService/NorthwindService.svc/&lt;/a&gt; . If you are new to this then I suggest you take a look at &lt;a href="http://msdn.microsoft.com/en-us/data/cc668810.aspx"&gt;Getting Started with Data Services&lt;/a&gt; section on MSDN&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In order to code the client lets first create a Data Service proxy using the tool DataSvcUtil.exe . Open up Visual Studio command prompt and type the following &lt;/p&gt;  &lt;p&gt;c:\Users\bindeshv&amp;gt;DataSvcUtil /out:NorthwindService.cs /language:CSharp /uri:http://localhost:54560/MyDataService/NorthwindService.svc/&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next go ahead and add this to your WinForms project as an existing item. Once done you need to add the Using reference to the newly added chsarp namespace.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Add a RDLC file to the project as shown below &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_1.png" width="807" height="488" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next we need to define the data source for the local report. In order to do that bring up the Data Sources explore (from Visual Studio Menu , Data &amp;gt; Show Data Sources) and then click on Add New Data Source in the Data Source Explorer. This will start a wizard and in the first window choose Service as the Data Source type and in the next window type in the url of your WCF Data Service as shown below and click Go &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_2.png" width="625" height="508" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Go ahead and give a namespace and then click on OK button.&amp;#160; Once the service reference is added to the project and since WCF Data Services exposes entity you need to choose the object that you will bind the report to. In order to do this again go to the Data Source Explorer and then Add a new Data Source but this time choose Object instead of service and point it to the WCF Service that was added to the project like shown below &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_3.png" width="655" height="508" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once the object is added to the Data Source Explore you can proceed with the normal design of the report by dragging in a table component and then adding the necessary fields &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_4.png" width="260" height="338" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_5.png" width="634" height="220" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now we need to add the Report Parameter, in this case I will specify the Employee ID as input for filtering , so that we see details of only one specific employee. In the Visual Studio Menu option go ahead and chose &lt;strong&gt;Report &amp;gt; Report Parameters..&amp;#160; &lt;/strong&gt;and the required parameter &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_6.png" width="827" height="618" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once the parameter is defined you need to specify it in the Reports Table Properties Filter section as shown below &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_8.png" width="644" height="541" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once the filtering is done go ahead and add a Report Viewer control to the form. Remember we need to device our own parameter for Reports in case of local report. Here is how my form looks after the design is done &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_9.png" width="748" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And here is how the code behind looks like &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: green"&gt;     &lt;font size="2" face="Lucida Console"&gt;  //Form level member
       &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Employees&lt;/span&gt;&amp;gt; empList = &lt;span style="color: blue"&gt;null &lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: blue"&gt;       private void &lt;/span&gt;Form1_Load(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(empList == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
            {

                NorthwindModel.&lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;entitiesContext = &lt;span style="color: blue"&gt;new &lt;/span&gt;NorthwindModel.&lt;span style="color: #2b91af"&gt;NorthwindEntities&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;http://localhost:54560/MyDataService/NorthwindService.svc/&amp;quot;&lt;/span&gt;));
                &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: blue"&gt;try
                &lt;/span&gt;{

                   empList = (&lt;span style="color: blue"&gt;from &lt;/span&gt;emps &lt;span style="color: blue"&gt;in &lt;/span&gt;entitiesContext.Employees
                               &lt;span style="color: blue"&gt;select &lt;/span&gt;emps).ToList&amp;lt;&lt;span style="color: #2b91af"&gt;Employees&lt;/span&gt;&amp;gt;();
                

                    &lt;span style="color: #2b91af"&gt;ReportDataSource &lt;/span&gt;rds = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ReportDataSource&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;DataServiceForms_NorthwindReference_Employees&amp;quot;&lt;/span&gt;, empList);
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.reportViewer1.LocalReport.DataSources.Clear();
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.reportViewer1.LocalReport.DataSources.Add(rds);

                }

                    
                &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;_ex)
                {
                    &lt;span style="color: #2b91af"&gt;MessageBox&lt;/span&gt;.Show(_ex.Message);

                }
            }

            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: green"&gt;//get all the employee ids and bind it 

            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;empIDs = &lt;span style="color: blue"&gt;from &lt;/span&gt;emps &lt;span style="color: blue"&gt;in &lt;/span&gt;empList
                         &lt;span style="color: blue"&gt;select &lt;/span&gt;emps.EmployeeID;
            &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i &lt;span style="color: blue"&gt;in &lt;/span&gt;empIDs)
            {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.comboBox1.Items.Add(i);
            }
            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: green"&gt;//set the combo to display the first item
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.comboBox1.SelectedIndex = 0;

            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: green"&gt;//bind parameters to the report
            &lt;/span&gt;BindParameter();
        }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;font size="2" face="Lucida Console"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color: blue"&gt;      private void &lt;/span&gt;BindParameter()
       {
           &lt;span style="color: #2b91af"&gt;ReportParameter &lt;/span&gt;param = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ReportParameter&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;EmpID&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;.comboBox1.SelectedItem.ToString());
           &lt;span style="color: blue"&gt;this&lt;/span&gt;.reportViewer1.LocalReport.SetParameters(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ReportParameter&lt;/span&gt;[] { param });
           &lt;span style="color: blue"&gt;this&lt;/span&gt;.reportViewer1.RefreshReport();
       }
&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="Lucida Console"&gt;       &lt;span style="color: blue"&gt;private void &lt;/span&gt;comboBox1_SelectedIndexChanged(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
       {
           BindParameter();
       }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The completed report looks like this &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_26.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DisplayingWCFDataServicedatainlocalrepor_A8BC/image_thumb_12.png" width="746" height="418" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Until next post .. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9926675" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="WCF DataService" scheme="http://blogs.msdn.com/bindeshv/archive/tags/WCF+DataService/default.aspx" /></entry><entry><title>Referring ADO.Net Entity project in a different project</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2009/09/04/referring-ado-net-entity-project-in-a-different-project.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2009/09/04/referring-ado-net-entity-project-in-a-different-project.aspx</id><published>2009-09-04T05:53:00Z</published><updated>2009-09-04T05:53:00Z</updated><content type="html">&lt;P&gt;&lt;U&gt;QuickPost:&lt;/U&gt; &lt;BR&gt;I just now answered a question on the forum about one of the errors that might take you a while to figure out. Assume the following scenario, you have a Data Model Project designed as class library for EntityFramework and you have a middle layer or a UI Layer and you are referring the EF Assembly. When you try to run the project you get the&amp;nbsp; following error &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000 size=2&gt;"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;If you go check the EntityProject you might find the connectionstring information inside the app.config. This is created automatically by the Entity Model Designer wizard. The issue is that when you refer the EntityProject inside another project the dll for the entity model is loaded in the context of the current application and hence it tries to read the connectionstring from the current app.config/web.config file.&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The fix is to add the connectionstring information from the EntityProject&amp;nbsp; to your referring project’s app.config or web.config under the &amp;lt;connectionstrings&amp;gt; element , like this &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
   &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;SchoolEntities&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;connectionString&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;metadata=res://*/SchoolModel.csdl|res://*/SchoolModel.ssdl|res://*/SchoolModel.msl;provider=System.Data.SqlClient;provider connection string=&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;&amp;amp;quot;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Data Source=.\yukon;Initial Catalog=School;Integrated Security=True;MultipleActiveResultSets=True&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;&amp;amp;quot;&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;providerName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;System.Data.EntityClient&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Here is the forum post on this &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d0261818-ed96-43b6-adfd-3c146d8e1a68/"&gt;http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/d0261818-ed96-43b6-adfd-3c146d8e1a68/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9891188" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Using EntityBag with EntityFramework over WCF</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2009/08/28/using-entitybag-with-entityframework-over-wcf.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2009/08/28/using-entitybag-with-entityframework-over-wcf.aspx</id><published>2009-08-28T11:07:36Z</published><updated>2009-08-28T11:07:36Z</updated><content type="html">&lt;p&gt;I was going through the article published in MSDN by Daniel Simmons about the N-Tier Patterns &lt;a title="http://msdn.microsoft.com/en-us/magazine/dd882522.aspx" href="http://msdn.microsoft.com/en-us/magazine/dd882522.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/dd882522.aspx&lt;/a&gt; and came across the EntityBag implementation. So I went through couple of posts by Daniel on the EntityBag stuff to acquire the working knowledge and get started with EntityBag.&amp;nbsp; The project is hosted in &lt;a href="http://code.msdn.microsoft.com/entitybag/"&gt;codeplex&lt;/a&gt; &lt;/p&gt; &lt;p&gt;There were a couple of issues that I faced in getting it to run especially with changes in WCF and EF 3.5 sp1. So I thought of blogging about this to help get this working without much hassles.&lt;/p&gt; &lt;h5&gt;Changes Needed In EntityBag&lt;/h5&gt; &lt;p&gt;The first issue that you will face while compiling EntityBag project(Perseus) is the following error &lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000" size="1"&gt;&amp;nbsp; No overload for method 'GetEntityKey' takes '2' arguments&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Users\bindeshv\Code\perseus-1.1 entitybag\Perseus\UtilityExtensionMethods.cs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;The above error happens because ObjectContext.GetEntityKey(entitySetName, object) was a beta 3 method which was removed. Though there is an extension method inside UtilityExtensionMethod.cs&amp;nbsp; for IRleatedEnd like this &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityKey &lt;/span&gt;GetEntityKey(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IRelatedEnd &lt;/span&gt;relatedEnd)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.Assert(relatedEnd.IsEntityReference());&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;relationshipType = relatedEnd.GetType();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;PropertyInfo &lt;/span&gt;pi = relationshipType.GetProperty(&lt;span style="color: #a31515"&gt;"EntityKey"&lt;/span&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;EntityKey&lt;/span&gt;)pi.GetValue(relatedEnd, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;But the actual code calling this method is on ObjectContext in our CreateOriginalValuesObject method like this &lt;/p&gt; &lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;      EntityKey &lt;/span&gt;targetKey = context.GetEntityKey(fullEntitySetName, target);&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Since the intent here was to get the entity key for the target object and then get its ObjectStateEntry and then clone the original entries in the source to target, I changed the code to like this&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;          // EntityKey targetKey = context.GetEntityKey(target);
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ObjectStateEntry &lt;/span&gt;targetStateEntry = context.ObjectStateManager.GetObjectStateEntry(target);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;h5&gt;Changes In WCF Service&lt;/h5&gt;
&lt;p&gt;To test the program I created the following service contract and tried exposing it over WsHttpbinding &lt;/p&gt;&lt;pre class="code"&gt;   [&lt;span style="color: #2b91af"&gt;ServiceContract&lt;/span&gt;]
   &lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;INorthwind
  &lt;/span&gt;{
      [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;]
       &lt;span style="color: #2b91af"&gt;EntityBag&lt;/span&gt;&amp;lt;NorthwindModel.&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;&amp;gt; GetCustomerByID(&lt;span style="color: blue"&gt;string &lt;/span&gt;customerID);

      [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;]
      &lt;span style="color: blue"&gt;void &lt;/span&gt;UpdateCustomer(&lt;span style="color: #2b91af"&gt;EntityBag&lt;/span&gt;&amp;lt;NorthwindModel.&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;&amp;gt; customers);

      [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;] //for test&lt;br&gt;      &lt;span style="color: blue"&gt;int &lt;/span&gt;Test(&lt;span style="color: blue"&gt;int &lt;/span&gt;p);


  }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;But each time I tried getting this over to the client I will get a weird error on the client (took 2 days to figure this out) &lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;An error occurred while receiving the HTTP response to http://binvij-admin2.fareast.corp.microsoft.com/NorthwindSVC/Northwind.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;Server stack trace: &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;&amp;nbsp;&lt;font size="2" face="Consolas"&gt;&amp;nbsp; at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)&lt;/font&gt;&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)&lt;/font&gt;
&lt;p&gt;&lt;br&gt;I implemented a WCF trace, more details here on enabling the &lt;a href="http://msdn.microsoft.com/en-us/library/ms733025.aspx"&gt;trace&lt;/a&gt; , and saw the following logged in &lt;br&gt;&lt;br&gt;&amp;lt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;ExceptionType&amp;gt;System.ServiceModel.CommunicationException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;lt;/ExceptionType&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;lt;Message&amp;gt;&lt;strong&gt;There was an error while trying to serialize parameter http://tempuri.org/:GetCustomerByIDResult. The InnerException message was 'Type 'NorthwindModel.Customers' with data contract name 'Customers:http://schemas.datacontract.org/2004/07/NorthwindModel' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.&amp;lt;/&lt;/strong&gt;Message&amp;gt;&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;lt;StackTrace&amp;gt;at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest) at &lt;/font&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2" face="Consolas"&gt;&lt;/font&gt;&amp;nbsp; &lt;p&gt;&lt;font color="#0000ff" size="2" face="Consolas"&gt;The DataContractSerializer did not know about my Northwind.Customers type so I had to append my ServiceContract with &lt;/font&gt;&lt;pre class="code"&gt; [&lt;span style="color: #2b91af"&gt;ServiceContract&lt;/span&gt;]
 &lt;strong&gt;[&lt;span style="color: #2b91af"&gt;ServiceKnownType&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(NorthwindModel.&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;))]&lt;/strong&gt;
 
  &lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;INorthwind
  &lt;/span&gt;{
      [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;]
     
      &lt;span style="color: #2b91af"&gt;EntityBag&lt;/span&gt;&amp;lt;NorthwindModel.&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;&amp;gt; GetCustomerByID(&lt;span style="color: blue"&gt;string &lt;/span&gt;customerID);
&lt;font face="Verdana"&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;font face="Verdana"&gt;&lt;strong&gt;Note: This is missing in the client test project for EntityBag in the  demo&lt;br&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;font face="Verdana"&gt;After this I got an error at the client end, though I could see the WCF service sending the EntityBag&amp;lt;Customers&amp;gt; successfully. Here is the error&lt;br&gt;&lt;/font&gt;&lt;font face="Verdana"&gt; message &lt;br&gt;&lt;/pre&gt;&lt;/font&gt;&lt;br&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter &lt;/font&gt;&lt;a href="http://tempuri.org/:GetCustomerByIDResult"&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;http://tempuri.org/:GetCustomerByIDResult&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;. The InnerException message was 'Error in line 1 position 1808. Element '&lt;/font&gt;&lt;a href="http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType'"&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType'&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt; contains data of the '&lt;/font&gt;&lt;a href="http://schemas.datacontract.org/2004/07/NorthwindModel:Customers'"&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;http://schemas.datacontract.org/2004/07/NorthwindModel:Customers'&lt;/font&gt;&lt;/a&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt; data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Customers' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.&amp;nbsp; Please see InnerException for more details. &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;Server stack trace: &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&amp;amp; rpc) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp;amp; rpc) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) &lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)&lt;/font&gt;
&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&lt;/font&gt;&amp;nbsp; &lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&lt;font color="#000000" face="Verdana"&gt;We get this error due to an inappropriate setting of the buffer size for the binding in use. Check this link for more details&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;a title="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/e0bac3a6-f758-499b-9cab-32435b9887ea" href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/e0bac3a6-f758-499b-9cab-32435b9887ea"&gt;http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/e0bac3a6-f758-499b-9cab-32435b9887ea&lt;/a&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;&lt;br&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000" size="2"&gt;The fix is to increase the messagesize for both the client and the service in the config file&lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;wsHttpBinding&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;binding &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;AllowLargeMessages&lt;/span&gt;" &lt;span style="color: red"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;512000&lt;/span&gt;" &lt;span style="color: red"&gt;maxBufferPoolSize&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;512000&lt;/span&gt;" &lt;span style="color: blue"&gt;&amp;gt;
           &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;readerQuotas &lt;/span&gt;&lt;span style="color: red"&gt;maxArrayLength&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;5000000&lt;/span&gt;" &lt;span style="color: blue"&gt;/&amp;gt;
         &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;binding&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;wsHttpBinding&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And this should help getting your EntityBag serialized and Deserialized. &lt;/p&gt;
&lt;p&gt;Hope this helps !&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9888088" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>TechEd@Hyderabad-Day2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2009/05/15/teched-hyderabad-day2.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2009/05/15/teched-hyderabad-day2.aspx</id><published>2009-05-15T07:10:35Z</published><updated>2009-05-15T07:10:35Z</updated><content type="html">&lt;p&gt;Could not post the details yesterday coz I was tired attending many sessions. Here are the major points from the sessions I attended &lt;/p&gt;  &lt;h5&gt;&lt;font color="#0000ff"&gt;SQL Server 2008 -Beyond Relational Data by Praveen Srivatsa, Asthrasoft Consulting&lt;/font&gt;&lt;/h5&gt;  &lt;p&gt;&lt;strong&gt;XML Feature     &lt;br /&gt;&lt;/strong&gt;We deal with most of the data that is Non Relational in nature&lt;/p&gt;  &lt;p&gt;SQL Server 2008 has support for non relational data and it provides various data types &lt;/p&gt;  &lt;p&gt;You can use XQuery with Xml type. This allows you to specify a schema as well so you have some control over the type being stored. In general the data can be stored in XML type and retrieved as a relational model or vice versa&lt;/p&gt;  &lt;p&gt;Mapping of new date/time data types to xsd types &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;CLR Feature     &lt;br /&gt;&lt;/strong&gt;Lots of queries around this feature from many people. And I got scared about this atleast from the Support aspect of it . Developers wanted to put many things as a CLR object. And below is my thought about this &lt;/p&gt;  &lt;p&gt;Only 13 assemblies are allowed to be used called 'Blessed Assemblies'. UNSAFE load of an assembly can cause SQL Server memory corruption since it loads it inside MTL which is used for by sql server for external hosting of COM,CLR and out process providers &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Filestreams&lt;/strong&gt;    &lt;br /&gt;Benefits of filestream against BLOB types explained. Books OnLine(BOL) has more details on this.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;&lt;font color="#0000ff"&gt;ADO.NET Data Services Futures by Harish Ranganathan, Developer Evangelist&lt;/font&gt;&lt;/h5&gt;  &lt;p&gt;This talk was about ADO.Net Data Services offline still under development. Harish showed a smart client which can work offline. This is pretty pre-beta state. There were a lot of queries but most of them I believe would be clear if one goes through the ADO.Net synchronization services like one of the query was how does this handle a conflict of column&amp;#160; here is the MSDN page for this &lt;a title="http://msdn.microsoft.com/en-us/library/bb726002.aspx" href="http://msdn.microsoft.com/en-us/library/bb726002.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb726002.aspx&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;One of the interesting questions asked in the session was :-&lt;/p&gt;  &lt;p&gt;Can we keep version based copies of the modified records ? As of now I don’t this is thought about , but you can give your feedbacks on the Microsoft Connect site .   &lt;br /&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;h5&gt;&lt;font color="#0000ff"&gt;Modern Data Access Patterns and Implementations by Don Smith, Program Manager,P&amp;amp;P&lt;/font&gt;&lt;/h5&gt;  &lt;p&gt;This talk was an architect level discussion around the new patterns that should be incorporated for data access in particular with the DDD(Domain Driven Design). There is a lot being discussed about this in the P&amp;amp;P group and they are working on few patterns for data access, the code for which will be released once the VS 2010 beta is available. The pattern thats being explored are    &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Unit of work&lt;/li&gt;    &lt;li&gt;ActiveRecords&lt;/li&gt;    &lt;li&gt;Repository pattern     &lt;br /&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Check the codeplex site for more details &lt;a title="http://www.codeplex.com/dataguidance" href="http://www.codeplex.com/dataguidance"&gt;http://www.codeplex.com/dataguidance&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;&lt;font color="#0000ff"&gt;Building scalable applications using Velocity by Abid Khan, Program Manager, Velocity&lt;/font&gt; &lt;/h5&gt;  &lt;p&gt;Velocity is the new kid on the block was distributed caching. Many cool features in particular the load balancing. One of the internals is that this was purely build using .NET FX and leveraging the WCF as the backend for query over NamedPipes channel. Pretty much utilizes most of the concepts from clustering world and automatically detects any offline and online of hosted velocity server. Key takeaways    &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;As of now it does not invalidate the cache and refresh itself from the database. Going forward this will be thought about      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Please use a dedicated servers for velocity rather than clubbing it with the SQL Server or Web Farm     &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Velocity can be enabled for High Availability where in it will replicate the data across different hosted servers and thus available any time      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Can be used in any .net client &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Vision/Road Map&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;Being able to provide LINQ interfaces to query instead of the traditional get/put methods     &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Support for non .NET clients like PHP      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Availability for HPC (High Performance Computing)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;More details here at MSDN site &lt;a title="http://msdn.microsoft.com/en-au/data/cc655792.aspx" href="http://msdn.microsoft.com/en-au/data/cc655792.aspx"&gt;http://msdn.microsoft.com/en-au/data/cc655792.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;until next post :) &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9617680" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="TechED-09" scheme="http://blogs.msdn.com/bindeshv/archive/tags/TechED-09/default.aspx" /></entry><entry><title>TechEd@Hyderabad-Day1</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2009/05/13/teched-hyderabad-day1.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2009/05/13/teched-hyderabad-day1.aspx</id><published>2009-05-13T20:08:00Z</published><updated>2009-05-13T20:08:00Z</updated><content type="html">&lt;P&gt;Today I attended TechED-09. Here are the updates from the sessions I attended and some of the interesting things I found out &lt;/P&gt;
&lt;H5&gt;&lt;STRONG&gt;&lt;FONT color=#0080ff&gt;ASP.NET 4.0 Features from Stephen Walther, Program Manager, ASP.NET&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/H5&gt;
&lt;UL&gt;
&lt;LI&gt;Source based development, more focus on a neater and readable code&lt;/LI&gt;
&lt;LI&gt;Asp.net control’s client side ID code looked weird, so if you were using a client side script framework like JQuery it would be difficult to identify the control’s id in case a control lives inside a Master page. In ASP.Net 4.0 there is a property called &lt;FONT face=Consolas&gt;&lt;STRONG&gt;{Control}.ControlID&lt;/STRONG&gt; &lt;FONT face=Verdana&gt;that will allow to the users to specify a more neater feature&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Auto rendering of the code with "runat=server” attribute once picked from intelli sense&amp;nbsp; for common controls &lt;/LI&gt;
&lt;LI&gt;&amp;lt;asp:formview&amp;gt; and &amp;lt;asp:listview&amp;gt; now allows you to render them in div mode apart from the traditional table mode&lt;/LI&gt;
&lt;LI&gt;Viewstate can be disabled at the page level and then enabled for particular controls .&amp;nbsp; This is different from the EnableViewState mode since ViewState is inherited to the child controls whereas the EnableViewState does not &lt;/LI&gt;
&lt;LI&gt;Response.Redirect was not SEO friendly and search engine had issues with indexing them . Now asp.net 4.0 enables you to use Response.PermanentRedirect which emits a status code that is recognized by Search Engines(i believe it is status code 301 if i am remembering this correctly)&lt;/LI&gt;
&lt;LI&gt;New control added in asp.net 4 –&amp;gt;&amp;nbsp; QueryExtender . More about this here &lt;A title=http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/04/12/asp-net-queryextender-control-and-domaindatasource.aspx href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/04/12/asp-net-queryextender-control-and-domaindatasource.aspx" mce_href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/04/12/asp-net-queryextender-control-and-domaindatasource.aspx"&gt;http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/04/12/asp-net-queryextender-control-and-domaindatasource.aspx&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Features added to ASP.Net Core are &lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Cache Extensibility using Velocity&lt;/LI&gt;
&lt;LI&gt;Browser capabilities extensibility&lt;/LI&gt;
&lt;LI&gt;Session state compression using 2 main industry standards . One of them is GZIP&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;Some of the interesting questions asked by attendees are and there answers by Stephen&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Can i deploy ASP.NET application to the cloud(Microsoft Azure) ? &lt;BR&gt;&amp;nbsp; You can use visual studio 2008 azure toolkit to deploy the applications to Azure &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;When do we use Silverlight vs ASP.NET Web Forms vs ASP.NET MVC vs ASP.Net Ajax &lt;BR&gt;These are targeted to different needs and hence different problems. &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;How can i combine some features from asp.net 4.0 and dynamic data . Can we club them ? &lt;BR&gt;Yes you can. &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Check ASP.Net 4.0 and VS 2010 features White paper here &lt;A title=http://www.asp.net/learn/whitepapers/aspnet40/ href="http://www.asp.net/learn/whitepapers/aspnet40/" mce_href="http://www.asp.net/learn/whitepapers/aspnet40/"&gt;http://www.asp.net/learn/whitepapers/aspnet40/&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;&lt;STRONG&gt;&lt;FONT color=#0080ff&gt;ASP.Net MVC from Stephen Walther&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/H5&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;Well most of this talk was a walk through of a demo application and it was quite interesting. Some of the main features from MVC RTM that needs to be mentioned are &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SEO based URLs &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;PartialAjaxUpdate &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Velocity code templates available(this one refers to the java Velocity) &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Create your own code generation for View creation using T4 templates&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;&lt;FONT color=#0080ff&gt;LINQ Deep Drive from Sanjay Vyas&lt;/FONT&gt;&lt;/H5&gt;
&lt;P&gt;This session was like starting from the beginning like how Linq works. So I am not going to spend time detailing it , there is plenty information already available on the net. I will post some interesting questions asked in the session and my answers to the same &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Is the var keyword reflected at runtime ? &lt;BR&gt;No, the CompilerService actually converts it to a type but does not give it a name. It actually looks something like this&amp;nbsp; if you use ILDasm&lt;/LI&gt;
&lt;P&gt;&lt;FONT color=#008000 size=2 face=Consolas&gt;class [System.Core]System.Func`2&amp;lt;int32,&lt;STRONG&gt;&lt;FONT size=3&gt;class '&amp;lt;&amp;gt;f__AnonymousType0`1'&amp;lt;int32&amp;gt;&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt; LinqTest.Program::'CS$&amp;lt;&amp;gt;9__CachedAnonymousMethodDelegate4'&lt;/FONT&gt; &lt;/P&gt;
&lt;LI&gt;Can we use Linq for existing Datasets ? &lt;BR&gt;Yes, but only if you compile it with .net 3.5 framework. Here is more details about this on&amp;nbsp; MSDN &lt;A title=http://msdn.microsoft.com/en-us/library/bb386977.aspx href="http://msdn.microsoft.com/en-us/library/bb386977.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb386977.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb386977.aspx&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Whats the benefit of Property initializers , can’t i use constructors instead ? &lt;BR&gt;In a normal code you can but when you are writing a Linq Select statement and creating a new type the initializer becomes handy &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Is the return type of the following query an IList&amp;lt;int&amp;gt;&amp;nbsp; &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f0dfaf"&gt;List&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;int&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;list&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;=&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;new&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f0dfaf"&gt;List&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;int&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&amp;gt;() {&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;1&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;,&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;2&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;,&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;3&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;,&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;4&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;,&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;5&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;}; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;var &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;res&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;=&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;from &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;o &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;in &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;list&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;where &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;o &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #8acccf"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;select&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;(&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #eaeaac"&gt;new&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;{&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;iVal &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;=&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #f8ffc6"&gt;o&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #2e2e2e; COLOR: #d2d200"&gt;});&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; No, instead would be a type of IEnumerable&amp;lt;int&amp;gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Is there a performance hint while using Linq &lt;BR&gt;Not that we know of , but in case you find one, send us a repro code with the details of the delay&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;What is the difference between IQueryable and IEnumerable &lt;BR&gt;Graphically put &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/TechEdHyderabadDay1_13E56/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/TechEdHyderabadDay1_13E56/image_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/TechEdHyderabadDay1_13E56/image_thumb.png" width=870 height=521 mce_src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/TechEdHyderabadDay1_13E56/image_thumb.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Simply put IQueryable allows the mechanism for expression evaluation using queries. IEnumerator allows you to enumerate the collection. IQueryable on evaluation of a query expression gives you back a Enumerator for the resultant collection &lt;/P&gt;
&lt;P&gt;Until next post :) &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9609800" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="TechED-09" scheme="http://blogs.msdn.com/bindeshv/archive/tags/TechED-09/default.aspx" /></entry><entry><title>Using Stored Procedures That Return Non Entity Type</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/11/21/using-stored-procedures-that-return-non-entity-type.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/11/21/using-stored-procedures-that-return-non-entity-type.aspx</id><published>2008-11-21T16:33:31Z</published><updated>2008-11-21T16:33:31Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;In&amp;nbsp; the previous post I explained how to use a Stored Procedure in Entity Framework that returns an Entity Type.&amp;nbsp; However, if you try to map a stored procedure that is of a scalar type or returns an Array or List type then this won't work automatically with the current release of Entity Framework.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;In order to get this working you might need to implement a partial class and then specify the method. So lets take a look at how to use a Sproc that returns a Distinct Country names from Northwind.Customers&lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;CREATE PROCEDURE &lt;/span&gt;dbo.GetCountryList
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;AS
    BEGIN
     SET NOCOUNT ON 
      SELECT DISTINCT &lt;/span&gt;COUNTRY &lt;span style="color: blue"&gt;FROM &lt;/span&gt;CUSTOMERS &lt;span style="color: blue"&gt;ORDER BY &lt;/span&gt;COUNTRY &lt;/font&gt;&lt;/font&gt;&lt;span style="color: blue"&gt;&lt;font face="Consolas" size="2"&gt;ASC
     
  END&lt;/font&gt; 
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;First we might need to add the stored procedure inside the EDMX schema as we did in the previous stored procedure demo. So in the Model browser go ahead and the stored procedure by first adding it to Store Model and the adding the Function Import. Here is a screenshot&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="294" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_thumb_3.png" width="408" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Notice that I have the return type as Scalar.&amp;nbsp; This will generate the following CSDL element &lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;FunctionImport &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;GetCountryList&lt;/span&gt;" &lt;span style="color: red"&gt;ReturnType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Collection(String)&lt;/span&gt;" &lt;span style="color: blue"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;EntityContainer&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;font size="2"&gt;The return type element specify that its a Collection of String. Lets implement the partial class and write the code for calling the stored procedure &lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;:&lt;span style="color: blue"&gt;global&lt;/span&gt;::System.Data.Objects.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: #2b91af"&gt;ObjectContext
 &lt;/span&gt;{
    &lt;/font&gt;&lt;/font&gt;&lt;span style="color: gray"&gt;&lt;font face="cons" size="2"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/font&gt;&lt;/span&gt;&lt;span style="color: green"&gt;&lt;font face="cons" size="2"&gt;Implementation for calling a method that returns distinct country list
    &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;String collection &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Collection&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; GetCountryList()
    {
        &lt;span style="color: #2b91af"&gt;Collection&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; results = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Collection&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();

        &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: blue"&gt;try
        &lt;/span&gt;{
            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//get the connection object from the DataContext
            &lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DbConnection &lt;/span&gt;conn = &lt;span style="color: blue"&gt;this&lt;/span&gt;.Connection)
            {
                &lt;span style="color: #2b91af"&gt;DbCommand &lt;/span&gt;cmd = conn.CreateCommand();
                &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//command text is of the format of 'ContainerName.Stored Proc Name' 
                &lt;/span&gt;cmd.CommandText = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;"{0}.{1}"&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;.DefaultContainerName, &lt;span style="color: #a31515"&gt;"GetCountryList"&lt;/span&gt;);
                cmd.CommandType = System.Data.&lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt;.StoredProcedure;
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Connection.State != System.Data.&lt;span style="color: #2b91af"&gt;ConnectionState&lt;/span&gt;.Open)
                {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.Connection.Open();
                }

                &lt;span style="color: blue"&gt;var &lt;/span&gt;reader = cmd.ExecuteReader(&lt;span style="color: #2b91af"&gt;CommandBehavior&lt;/span&gt;.SequentialAccess);
                &lt;span style="color: blue"&gt;while &lt;/span&gt;(reader.Read())
                {
                    results.Add((&lt;span style="color: blue"&gt;string&lt;/span&gt;)reader[0]);
                }

                &lt;span style="color: blue"&gt;return &lt;/span&gt;results;
            }
        }
        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)
        {
            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//Todo: meaning full exception handling 
        &lt;/span&gt;}



        &lt;span style="color: blue"&gt;return &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Collection&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;)&lt;span style="color: blue"&gt;null&lt;/span&gt;;
       
    }
 }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;font size="2"&gt;Once this is compile you will be able to call this method from the front end using intellisense as shown in the screenshot below&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;br&gt;&lt;/font&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 0px; border-right-width: 0px" height="332" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_thumb.png" width="835" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Here is the code for forms binding&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;Form1_Load(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
       {
           &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;entities = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities&lt;/span&gt;())
           {
               &lt;span style="color: blue"&gt;this&lt;/span&gt;.customersBindingSource.DataSource = entities.CustByCountry(&lt;span style="color: #a31515"&gt;"Germany"&lt;/span&gt;);
               &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//bind the combo box
               //get the list of countries
               &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;countries = entities.GetCountryList();
               &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//for each country item in countries 
               &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;c &lt;span style="color: blue"&gt;in &lt;/span&gt;countries)
               {
                   &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="cons"&gt;&lt;span style="color: green"&gt;//add the country name
                   &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.toolStripComboBox1.Items.Add(c);

               }

           }
       }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;And here is the output of the forms binding&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="397" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresThatReturnNonEntity_FD50/image_thumb_4.png" width="737" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9131823" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Using Stored Procedures in Entity Framework</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/11/20/using-stored-procedures-in-entity-framework.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/11/20/using-stored-procedures-in-entity-framework.aspx</id><published>2008-11-20T15:22:37Z</published><updated>2008-11-20T15:22:37Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;Entity framework supports stored procedure. In this post I will explore how we can use stored procedures in entity framework.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;I have created a Windows based application with Northwind database model(EDMX) . And have the Customer and Orders table selected.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="367" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_thumb.png" width="568" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;In order to add a stored procedure open up the Model Browser and right click on the Model.Store in this case NorthwindModel.Store&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="205" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_thumb_1.png" width="413" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;And choose the required stored procedure. Next right click anywhere on the Edmx designer and choose Add &amp;gt; Function Import.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="347" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_thumb_2.png" width="911" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;This will bring up the wizard for adding Function. Choose the procedure you had added in the Model Store and choose the return type. In this case Customers which is of type Entity&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="300" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_thumb_3.png" width="411" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;This step will add a function to the EntityContext class. Here is how the generated code might look like &lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;        &lt;font face="Consolas" size="2"&gt; /// &amp;lt;summary&amp;gt;
        /// &lt;/font&gt;&lt;/span&gt;&lt;span style="color: green"&gt;&lt;font face="Consolas" size="2"&gt;There are no comments for NorthwindModel.CustByCountry in the schema.
        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public global&lt;/span&gt;::System.Data.Objects.&lt;span style="color: #2b91af"&gt;ObjectResult&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;&amp;gt; CustByCountry(&lt;span style="color: blue"&gt;string &lt;/span&gt;country)
        {
            &lt;span style="color: blue"&gt;global&lt;/span&gt;::System.Data.Objects.&lt;span style="color: #2b91af"&gt;ObjectParameter &lt;/span&gt;countryParameter;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;((country != &lt;span style="color: blue"&gt;null&lt;/span&gt;))
            {
                countryParameter = &lt;span style="color: blue"&gt;new global&lt;/span&gt;::System.Data.Objects.&lt;span style="color: #2b91af"&gt;ObjectParameter&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Country"&lt;/span&gt;, country);
            }
            &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;else
            &lt;/span&gt;{
                countryParameter = &lt;span style="color: blue"&gt;new global&lt;/span&gt;::System.Data.Objects.&lt;span style="color: #2b91af"&gt;ObjectParameter&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Country"&lt;/span&gt;, &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: blue"&gt;string&lt;/span&gt;));
            }
            &lt;span style="color: blue"&gt;return base&lt;/span&gt;.ExecuteFunction&amp;lt;&lt;span style="color: #2b91af"&gt;Customers&lt;/span&gt;&amp;gt;(&lt;span style="color: #a31515"&gt;"CustByCountry"&lt;/span&gt;, countryParameter);
        }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;font face="Consolas" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font face="ve" size="2"&gt;In my forms code I use an Object Data Source and have the following code for Forms_Load&lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;          using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;entities = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities&lt;/span&gt;())
            {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.customersBindingSource.DataSource = entities.CustByCountry(&lt;span style="color: #a31515"&gt;"Germany"&lt;/span&gt;);
                
            }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;&lt;font size="2"&gt;Here is the output&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_10.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="310" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/UsingStoredProceduresinEntityFramework_FAED/image_thumb_4.png" width="729" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9128782" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Getting Started With EntityClient in EntityFramework</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/11/10/getting-started-with-entityclient-in-entityframework.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/11/10/getting-started-with-entityclient-in-entityframework.aspx</id><published>2008-11-10T09:12:31Z</published><updated>2008-11-10T09:12:31Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;In this post I am going to illustrate how to use EdmGen and EntityClient to program with Entity Framework.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;EdmGen is utility shipped with Entity Framework for creation of the artifacts required for Entity Model Mapping viz the CSDL(Conceptual Schema Definition Language), SSDL(Storage Model) and MSL(Mapping Model). Though you can use the EDM wizard in Visual Studio 2008 sp1, but since you may find a lot of references how to use the EDM wizard on internet and really less information on usage of Edmgen, I resorted to this.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Lets see how to create the artifacts for our School Database Model. The School database can be generated from the scripts available at MSDN here. [Creating the School Sample Database &lt;a title="http://msdn.microsoft.com/en-us/library/bb399731.aspx" href="http://msdn.microsoft.com/en-us/library/bb399731.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb399731.aspx&lt;/a&gt;]&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Open up Visual Studio 2008 Command Prompt and then fire the following command &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas" size="2"&gt;&lt;strong&gt;c:\&amp;gt; edmgen /connectionstring:"server=.\yukon;integrated security=true;database=school" /mode:FullGeneration /project:"EntityClientDemo"&lt;/strong&gt;&lt;/font&gt; &lt;p&gt;&lt;font size="2"&gt;Here is the explanation of&amp;nbsp; the switches used with Edmgen.exe&lt;/font&gt; &lt;ul&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;strong&gt;/ConnectionString&lt;/strong&gt; : specifies the connection string used for connecting to the database&lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font size="2"&gt;/&lt;strong&gt;FullGeneration&lt;/strong&gt; : Generate ssdl, msl, csdl, and objects from the database&lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;strong&gt;/Project&lt;/strong&gt; : The base name to use for the artifact files. &lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;NOTE: You need to specify either this switch or all the /OutXXXXX switches if you are using the /FullGeneration switch. To get more details on the various switches use EdmGen -help&lt;/em&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Next, go ahead and create a new project in Visual Studio 2008. For this post, I created a console application. And add reference System.Data.Entity.&lt;/font&gt; &lt;p&gt;&lt;font size="2"&gt;Here is the code &lt;/font&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;EntityConnection &lt;/span&gt;conn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityConnection&lt;/span&gt;())
           {
               &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;try 
               &lt;/span&gt;{
                  conn.ConnectionString =&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt; &lt;span style="color: #a31515"&gt;@"Metadata=C:\Users\BindeshV\Documents\Visual Studio 2008\Projects\EntityFramework\EFClientDemo\EFClientDemo\Artifacts;" &lt;/span&gt;+
 &lt;span style="color: #a31515"&gt;@"Provider=System.Data.SqlClient;"&lt;/span&gt;+
 @&lt;span style="color: #a31515"&gt;"Provider Connection String='Server=.\yukon;Integrated Security=yes;Database=School'"&lt;/span&gt;;
                   conn.Open();
                   &lt;span style="color: #2b91af"&gt;EntityCommand &lt;/span&gt;cmd = conn.CreateCommand();
                   cmd.CommandText = &lt;span style="color: #a31515"&gt;"Select C.CourseID,C.Title from EFClientDemoContext.Course as C"&lt;/span&gt;;
                   cmd.CommandType = &lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt;.Text;
                   &lt;span style="color: #2b91af"&gt;EntityDataReader &lt;/span&gt;reader = cmd.ExecuteReader(&lt;span style="color: #2b91af"&gt;CommandBehavior&lt;/span&gt;.SequentialAccess);

                   &lt;span style="color: blue"&gt;while&lt;/span&gt;(reader.Read())
                   {
                       &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Course Id={0} Course Title={1}"&lt;/span&gt;,reader.GetInt32(0),reader.GetString(1));
                   }
              }
              &lt;span style="color: blue"&gt;catch&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)
               {
                   &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(ex.StackTrace);
               }

           }

           &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Read();&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;font size="2"&gt;Usage of EntityClient is somewhat similar to that of the SqlClient. &lt;/font&gt;
&lt;p&gt;&lt;font size="2"&gt;The ConnectionString property of the EntityConnection object has 3 keywords &lt;/font&gt;
&lt;ul&gt;
&lt;li&gt;&lt;font size="2"&gt;Metadata - The path where are the artifacts reside. In this case the .csdl,.ssdl and msl.&lt;/font&gt;&lt;/li&gt;
&lt;li&gt;&lt;font size="2"&gt;Provider - The ADO.NET provider used to connect to the Database Store&lt;/font&gt;&lt;/li&gt;
&lt;li&gt;&lt;font size="2"&gt;Provider Connection String - The regular connection string &lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;font size="2"&gt;Notice that the CommandText uses the format of ContainerName.EntityName . In our case the EdmGen tool had the following information for Container Name &lt;/font&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Schema &lt;/span&gt;&lt;span style="color: red"&gt;Namespace&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;EFClientDemo&lt;/span&gt;" &lt;span style="color: red"&gt;Alias&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Self&lt;/span&gt;" &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;http://schemas.microsoft.com/ado/2006/04/edm&lt;/span&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &lt;strong&gt; &amp;lt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color: #a31515"&gt;EntityContainer &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;EFClientDemoContext&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;&lt;font size="2"&gt;Here is the output of the program&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/GettingStartedWithEntityClientinEntityFr_A493/BlogEFClientDemoOutput.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="343" alt="BlogEFClientDemoOutput" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/GettingStartedWithEntityClientinEntityFr_A493/BlogEFClientDemoOutput_thumb.jpg" width="673" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Thanks&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9056907" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Retrieving Identity or AutoGenerated Column in ADO.NET</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/10/31/retrieving-identity-or-autogenerated-column-in-ado-net.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/10/31/retrieving-identity-or-autogenerated-column-in-ado-net.aspx</id><published>2008-10-31T16:06:24Z</published><updated>2008-10-31T16:06:24Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;I recently handled an issue where customer was facing difficulty in picking up the Auto Generated primary key column in &lt;font face="con"&gt;DataAdapter.Update()&lt;/font&gt; call. Looking around on the internet I saw many posts on the forums regarding how to get this value. So thought of posting it here &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;There are 2 ways to go about this &lt;/font&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;font size="2"&gt;Using an output parameter &lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font size="2"&gt;Using a Select statement inside the same batch as that of the insert &lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;font size="2"&gt;I see the output parameter being already documented in MSDN here &lt;/font&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx" href="http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;The second method is documented like this MSDN and will be our topic of concern, &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Arial" color="#0080c0" size="2"&gt;If your insert command executes a batch that includes both an INSERT statement and a SELECT statement that returns the new identity value, then you can retrieve the new value by setting the UpdatedRowSource property of the insert command to UpdateRowSource.FirstReturnedRecord&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Here is how to go about this :&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;I have a sample table called Categories with the following schema&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/RetrievingIdentityorAutoGeneratedCol.NET_100AC/CategoriesTable.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="157" alt="CategoriesTable" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/RetrievingIdentityorAutoGeneratedCol.NET_100AC/CategoriesTable_thumb.jpg" width="399" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Here the CategoryId column is set to Identity&lt;/p&gt; &lt;p&gt;Next I created the stored procedure that will help insert the CategoryName column. Here is how the definition looks like &lt;/p&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;CREATE PROCEDURE &lt;/span&gt;InsertCategory
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: gray"&gt;(
    &lt;/span&gt;@CategoryName &lt;span style="color: blue"&gt;nvarchar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;50&lt;/font&gt;&lt;/font&gt;&lt;span style="color: gray"&gt;&lt;font face="con" size="2"&gt;)
)
&lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;as
begin

    Insert Into &lt;/span&gt;Categories&lt;span style="color: gray"&gt;(&lt;/span&gt;CategoryName&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: gray"&gt;)
    &lt;/span&gt;&lt;span style="color: blue"&gt;values &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;@CategoryName&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span&gt;)
   &lt;strong&gt; Select &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color: magenta"&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;span style="color: gray"&gt;() &lt;/span&gt;&lt;span style="color: blue"&gt;as &lt;/span&gt;CategoryId&lt;/strong&gt;
&lt;span style="color: blue"&gt;end&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;Notice that in the procedure the last T-SQL statement is a Select statement which queries the Identity value in the scope and returns it as the name of the column for the primary key.&lt;/p&gt;
&lt;p&gt;Once this is in place lets take a look at the ADO.NET code &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;         &lt;font face="con" size="2"&gt;   string &lt;/font&gt;&lt;/span&gt;&lt;font face="con" size="2"&gt;strCatName;
            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Enter the category"&lt;/span&gt;);
            strCatName = &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();

            &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SqlConnection &lt;/span&gt;conn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt;())
            {
                &lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: blue"&gt;try
                &lt;/span&gt;{
                    conn.ConnectionString = &lt;span style="color: #a31515"&gt;@"Server=.\yukon;integrated security=true;initial catalog=Test"&lt;/span&gt;;
                    conn.Open();

                    &lt;span style="color: #2b91af"&gt;DataSet &lt;/span&gt;ds = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataSet&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Test"&lt;/span&gt;);
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//create an adapter specifying a select
                    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlDataAdapter &lt;/span&gt;aDap = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlDataAdapter&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Select * From Categories"&lt;/span&gt;, conn);
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//specify the insert command for the aDap
                    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand &lt;/span&gt;insertCommand = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;();
                    insertCommand.CommandText = &lt;span style="color: #a31515"&gt;"InsertCategory"&lt;/span&gt;;
                    insertCommand.CommandType = &lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt;.StoredProcedure;
                    insertCommand.Parameters.Add(&lt;span style="color: #a31515"&gt;"@CategoryName"&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;SqlDbType&lt;/span&gt;.NVarChar, 50, &lt;span style="color: #a31515"&gt;"CategoryName"&lt;/span&gt;);
                    insertCommand.UpdatedRowSource = &lt;span style="color: #2b91af"&gt;UpdateRowSource&lt;/span&gt;.FirstReturnedRecord;
                    insertCommand.Connection = conn;
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//bind the insertCommand to DataAdapter
                    &lt;/span&gt;aDap.InsertCommand = insertCommand;
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//fill the dataset
                    &lt;/span&gt;aDap.Fill(ds, &lt;span style="color: #a31515"&gt;"Categories"&lt;/span&gt;);

                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//get the Categories table
                    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTable &lt;/span&gt;categoriesTbl = ds.Tables[&lt;span style="color: #a31515"&gt;"Categories"&lt;/span&gt;];

                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//create a new row
                    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataRow &lt;/span&gt;newRow = categoriesTbl.NewRow();
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//fill in the values for the column
                    &lt;/span&gt;newRow[&lt;span style="color: #a31515"&gt;"CategoryName"&lt;/span&gt;] = strCatName;
                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//add the new row
                    &lt;/span&gt;categoriesTbl.Rows.Add(newRow);

                    &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="con"&gt;&lt;span style="color: green"&gt;//update the adapter
                    &lt;/span&gt;aDap.Update(ds, &lt;span style="color: #a31515"&gt;"Categories"&lt;/span&gt;);

                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Printing updated results"&lt;/span&gt;);
                    PrintResults(ds);

                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Read();


                }
                &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SqlException &lt;/span&gt;ex)
                {
                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(ex.Message);
                    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Read();
                }

            }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;font face="time" size="2"&gt;Notice that in the insertCommand above I have the following property set&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="cons" size="2"&gt;insertCommand.UpdatedRowSource = &lt;span style="color: #2b91af"&gt;UpdateRowSource&lt;/span&gt;.FirstReturnedRecord;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="time" size="2"&gt;This is specifying the adapter that once updated the first returned record is mapped to the changed row in DataSet. And since we are sending the CategoryId&amp;nbsp; which the DataTable already knows, the DataAdapter.Update() will be able to map the column and put the value for you.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="time" size="2"&gt;Hope this helps !&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9026567" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="ADO.NET" scheme="http://blogs.msdn.com/bindeshv/archive/tags/ADO.NET/default.aspx" /></entry><entry><title>Web Client Software Factory-The Web Patterns</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/09/07/web-client-software-factory-the-web-patterns.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/09/07/web-client-software-factory-the-web-patterns.aspx</id><published>2008-09-07T06:41:06Z</published><updated>2008-09-07T06:41:06Z</updated><content type="html">&lt;p&gt;This post is in continuance with the last post&amp;#160; I had on WCSF. In this post I will briefly elaborate on various patterns in web development&amp;#160; and the general terms used to help you understand WCSF in a comprehensive way.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;The View Presenter Pattern&lt;/h5&gt;  &lt;p&gt;Asp.Net is a great web development platform that enables you to be productive from day one. However, careful understanding of patterns is needed in order to program better.&lt;/p&gt;  &lt;p&gt;I have been myself part of many projects where the code behind page will run into many lines of code, embedding the business logic and database calls. A generic pattern I have seen with many code behind pages is that they have the code for interaction for the user events, code to interact with the domain/database data and present it to the end user by &lt;em&gt;databind&lt;/em&gt; calls. Though for a small project this might not be an issue at all, but in a enterprise level application, this approach, will end up having complex code behind making it difficult to test and maintain. The other concern here would be that I would need to rewrite or copy this entire stuff should I need them in other module(s).&lt;/p&gt;  &lt;p&gt;The solution here is to go for &lt;strong&gt;View-Presenter&lt;/strong&gt;. Separate the responsibilities for the visual display and the event handling behavior into different classes, the view and the presenter. The view class &lt;em&gt;(.aspx.cs page&lt;/em&gt;) manages the controls on the page, and it forwards events to a presenter class. Once the presenter class gets the events it is responsible for communicating with the Business Logic Layer and responding back with the data/behavior to the View. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/clip_image002_2.gif"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="65" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/clip_image002_thumb.gif" width="232" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In the View-Presenter pattern the view does not know about the Model. The interaction with the Model is completely a responsibility of the Presenter. This makes it easy to have a TDD with Mock Implementations.&lt;/p&gt;  &lt;h6&gt;Two Important Patterns for implementing View Presenter&lt;/h6&gt;  &lt;p&gt;You can implement the View-Presenter using &lt;strong&gt;Observer Pattern &lt;/strong&gt;or &lt;strong&gt;Application Controller&lt;/strong&gt; pattern. In the Observer Pattern the Presenter listens to the events from the model and updates the corresponding events. The reference implementation of WCSF uses Application Controller pattern, explained in the next topic&lt;/p&gt;  &lt;h5&gt;The Application Controller Pattern&lt;/h5&gt;  &lt;p&gt;In the Application Controller pattern all the views interact with a single object which takes care of the page flow and the screen navigation logic. The Controller can also interact with the Model and define the flow based on the state of the Model.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/clip_image004_2.gif"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="117" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/clip_image004_thumb.gif" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;Dependency Injection(IOC)&lt;/h5&gt;  &lt;p&gt;The better way to describe the issue would by showing a code snippet. Here we have a BankAccount object which tries to insert a debit amount&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="130" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb.png" width="611" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The issue with this approach here is the heavy dependency of &lt;strong&gt;DatabaseService&lt;/strong&gt; class on &lt;strong&gt;SqlClient.&lt;/strong&gt;The concerns here are &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt; We need to rewrite the source code for DatabaseService.Insert to change the dependency from SqlClient to some other provider. Yes, I know that for most us this is not a changing factor, but lets say the product needs to be shipped to a client who wants to implement the backend as MySQL ? &lt;/li&gt;    &lt;li&gt;The concrete implementation of the dependencies must be available at compile time. &lt;/li&gt;    &lt;li&gt;The DatabaseService class is difficult to test in isolation because it has a direct reference to SqlClient (therefore, you cannot replace the service implementations with mock implementations). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We want to decouple the dependencies here so that we can &lt;em&gt;replace/update&lt;/em&gt; the dependencies with minimal affect to the consumer and also help in Testing using mock implementations.&amp;#160; Dependency Injection comes to our help here. Here we have a Constructor Injection that will help us various implementations &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="249" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb_1.png" width="530" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="367" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb_2.png" width="537" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="332" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb_3.png" width="541" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_10.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="341" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb_4.png" width="598" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Notice : I am having an inference of the Type of Database in use, this in order to build the appropriate collection syntax to pass inside the parameters. If the implementation used NHibernate or EFX any other ORM then this would not be needed. To demonstrate the concept this approach is simple.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now that we have different implementations I can switch over to any provider &lt;strong&gt;neatly and efficiently &lt;/strong&gt;and also test using Mock Object implementation of my choice. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_12.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="544" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheWebPatterns_80E5/image_thumb_5.png" width="693" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8929774" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Patterns" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Patterns/default.aspx" /></entry><entry><title>Web Client Software Factory-The Concept</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/09/07/web-client-software-factory-the-concept.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/09/07/web-client-software-factory-the-concept.aspx</id><published>2008-09-07T06:23:00Z</published><updated>2008-09-07T06:23:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this series, I will help you get started with WCSF developed by Patterns and Practices team at Microsoft. If you are a web developer then this Software Factory will be of great help for you in your upcoming web projects. &lt;/P&gt;
&lt;P&gt;Let me start of with the basics in order to speed you up with certain basic concepts which would be helpful to understand WCSF. Although the WCSF documentation is a great one, but if you are lazy as I am , you would not want to spend a lot of time in reading it but would be happy to see a quick get start on this.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Software Factory&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;A software factory is a proven set of standard industry practices based on Software Engineering Principles , that helps the architect build a uniform set of software assets and tools. &lt;/P&gt;
&lt;P&gt;Software assets include reusable code components, documentation, and reference implementations. Software tools include wizards, code generators, and visual designers. Typically, a software factory provides templates and other tools to help a development team quickly start development of new applications. It also continues to assist the developers by providing guidance and automation of the prescribed development activities throughout the application development life cycle. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Guidance Package&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Guidance Package consists of set of recipes and templates to allow developers to perform a set of development tasks defined by the package author. In the absence of this, the developer would have to do these tasks manually. Guidance Package enables the developer to automate these recipes. As an example Web Client Software Factory has a Recipe that allows the developer to add a View. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image001_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image001_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=446 alt=clip_image001 src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image001_thumb.jpg" width=430 border=0 mce_src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image001_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Composite Web Applications&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Pictures talk more than the words. Here in this diagram we have different pieces of components that come together to give the user all the required features. However, the user does not know of the various components, since this is all integrated to one single web application to give an end user experience.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image003_2.gif" mce_href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image003_2.gif"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=264 alt=clip_image003 src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image003_thumb.gif" width=488 border=0 mce_src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/WebClientSoftwareFactoryTheConcept_7D02/clip_image003_thumb.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This entire principle is known as Composite Pattern.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Shell And Modules&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;A Composite Pattern generally divides the solution in to Shells and Modules. Shells are responsible for giving the user interface structure whereas the modules are functionality discrete pieces, integrate with user interface and communicate with Shells.&lt;/P&gt;
&lt;P&gt;This helps in separation of concerns and thus helps in providing an environment for Test Driven Development and also helps separation of roles between developers.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8929717" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="Patterns" scheme="http://blogs.msdn.com/bindeshv/archive/tags/Patterns/default.aspx" /></entry><entry><title>File IO System in .NET</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/07/24/file-io-system-in-net.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/07/24/file-io-system-in-net.aspx</id><published>2008-07-24T23:53:01Z</published><updated>2008-07-24T23:53:01Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;I am preparing for &lt;em&gt;MCTS Exam 70-536: Microsoft .NET Framework 2.0 - Application Development&lt;/em&gt; &lt;em&gt;Foundation&lt;/em&gt; and came across the File IO System. So taking this opportunity here to post few details on the I/O streams to help understand the workings, specially for someone who is just getting started.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;The following diagram below describes the I/O Class hierarchy in .Net Framework 2.0.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/FileIOSystemin.NET_532F/FileIoStreamClass.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="479" alt="File IO System" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/FileIOSystemin.NET_532F/FileIoStreamClass_thumb.jpg" width="700" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h5&gt;&lt;strong&gt;Streams&lt;/strong&gt;&amp;nbsp; &lt;/h5&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;font size="2"&gt;Represents the base class for many Stream based classes. Streams generally mean a sequence of bytes either flowing in to the system or flowing outside the system.&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Specialised Streams &lt;/strong&gt;These are streams specialized for a specific set of stream operations. Basically these streams inherit from the System.IO.Stream. The examples of such streams include :&lt;/font&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;font color="#404040"&gt;System.IO.FileStream&lt;/font&gt; &lt;/strong&gt;Represents a stream that can aid in reading and writing to a disk file or standard input or standard output.&lt;br&gt;&lt;/font&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;font color="#404040"&gt;System.IO.MemoryStream&lt;/font&gt;&lt;/strong&gt; Represents a stream that can help in writing/reading to a memory location as a buffer, once the operation is done it can be transferred to another medium, perhaps to a disk file. MemoryStream's can reduce the need for temporary buffers or files in an application.&amp;nbsp; &lt;br&gt;&lt;/font&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;font color="#404040"&gt;System.IO.BufferedStream&lt;/font&gt;&lt;/strong&gt; Represents a block of bytes in memory acting as a cache and helps reduce the call to Operating System. Once the buffer operation is done the bytes can be transferred to the appropriate medium.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h5&gt;Writers And Readers&lt;/h5&gt; &lt;p&gt;&lt;font size="2"&gt;These classes help in reading/writing to specialized streams. As shown in the above class diagram we have specialized readers and writers. For text related read/write operations we can use &lt;font face="Lucida Console"&gt;StreamReader&lt;/font&gt; or &lt;font face="Lucida Console"&gt;StreamWriter&lt;/font&gt; and &lt;font face="Lucida Console"&gt;StringReader&lt;/font&gt; and &lt;font face="Lucida Console"&gt;StringWriter&lt;/font&gt; classes. All of these classes inherits from &lt;font face="Lucida Console"&gt;TextReader&lt;/font&gt; and &lt;font face="Lucida Console"&gt;TextWriter&lt;/font&gt; abstract base class. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;The &lt;font face="Lucida Console"&gt;StreamWriters&lt;/font&gt; or &lt;font face="Lucida Console"&gt;StreamReaders&lt;/font&gt; helps in writing or reading text streams to or from the underlying stream. Whereas the &lt;font face="Lucida Console"&gt;StringWriter&lt;/font&gt; or &lt;font face="Lucida Console"&gt;StringReader&lt;/font&gt; helps in writing or reading from inline memory strings.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Another special kind of readers and writers are the &lt;font face="Lucida Console"&gt;BinaryReader&lt;/font&gt; and &lt;font face="Lucida Console"&gt;BinaryWriter &lt;font face="Verdana"&gt;classes&lt;/font&gt;.&lt;/font&gt;These classes help in reading/writing binary data.&lt;/font&gt;&lt;/p&gt; &lt;h5&gt;Steps In Reading/Writing&lt;/h5&gt; &lt;ol&gt; &lt;li&gt;&lt;font size="2"&gt;The first step is to have a stream representing the medium to which you want to read/write the data&lt;br&gt;&lt;/font&gt; &lt;li&gt;&lt;font size="2"&gt;Have an appropriate reader/writer depending upon the type of data you are interested in&lt;br&gt;&lt;/font&gt; &lt;li&gt;&lt;font size="2"&gt;Use the readers/writers method to perform the data read/write operation&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h5&gt;A Demo&lt;/h5&gt; &lt;p&gt;&lt;font size="2"&gt;Though you can get more specific details on reading and writing to a file however I would like to put few lines to indicate my above theory on basic steps in Reading/Writing a file. So here we go&lt;/font&gt; &lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;  &lt;span class="kwrd"&gt;Try&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; theFile &lt;span class="kwrd"&gt;As&lt;/span&gt; FileStream&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        theFile = File.Create(fileName)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;         &lt;span class="kwrd"&gt;Dim&lt;/span&gt; sw &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; StreamWriter(theFile)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;         sw.WriteLine(&lt;span class="str"&gt;"this is a file"&lt;/span&gt;)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;         sw.Close()&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;  &lt;span class="kwrd"&gt;Catch&lt;/span&gt; ex &lt;span class="kwrd"&gt;As&lt;/span&gt; Exception&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        Console.WriteLine(ex.Message)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;  &lt;span class="kwrd"&gt;End&lt;/span&gt; Try&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8770070" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/bindeshv/archive/tags/.NET/default.aspx" /></entry><entry><title>Demystifying SQL-Oracle Distributed Query Issues</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/05/21/demystifying-sql-oracle-distributed-query-issues.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/05/21/demystifying-sql-oracle-distributed-query-issues.aspx</id><published>2008-05-21T21:04:22Z</published><updated>2008-05-21T21:04:22Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;While running the following query distributed query&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;select * from openrowset&lt;/strong&gt;&lt;/font&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;('OraOLEDB.Oracle','oradb';'scott';'pwd1234$',&lt;/strong&gt;&lt;/font&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;'select * from emp')&lt;/strong&gt;&lt;/font&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;I got the following error message :&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font size="1"&gt;Msg 15281, Level 16, State 1, Line 1&lt;br&gt;SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online. &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;This is because by default in SQL Server 2005 Ad Hoc Queries are disabled. You can enable it by opening up SQL Server 2005 Configuration Wizard and click on Surface Area Configuration For Features and under Database Engine click Enable OPENROWSET and OPENDATASOURCE support.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DemystifyingFewCommonLinkedServerIssues_4EE6/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="449" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DemystifyingFewCommonLinkedServerIssues_4EE6/image_thumb.png" width="786" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;You get the error&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font size="1"&gt;Msg 7399, Level 16, State 1, Line 3&lt;br&gt;The OLE DB provider "OraOLEDB.Oracle" for linked server "(null)" reported an error. The provider did not give any information about the error.&lt;br&gt;Msg 7330, Level 16, State 2, Line 3&lt;br&gt;Cannot fetch a row from OLE DB provider "OraOLEDB.Oracle" for linked server "(null)".&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;The reasons why you get this error&amp;nbsp; is because "Allow in Process" is not enabled for the provider. You can enable this option by opening up Linked Server &amp;gt; Providers and checking on "Allow in Process"&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DemystifyingFewCommonLinkedServerIssues_4EE6/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="317" alt="image" src="http://blogs.msdn.com/blogfiles/bindeshv/WindowsLiveWriter/DemystifyingFewCommonLinkedServerIssues_4EE6/image_thumb_1.png" width="805" border="0"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;This option is needed because SQL Server will pass proper authentication across the remote procedure only when the Ole DB provider is configured for in process.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8528987" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author></entry><entry><title>C# 3.0 Features Basics For LINQ PART II</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/03/22/c-3-0-features-basics-for-linq-part-ii.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/03/22/c-3-0-features-basics-for-linq-part-ii.aspx</id><published>2008-03-22T12:05:52Z</published><updated>2008-03-22T12:05:52Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;Continuing from part 1, here I will go one more step further and explain the language constructs basics in C# 3.0 which will help us in writing a LINQ query. &lt;/font&gt;&lt;/p&gt; &lt;h3&gt;Lambda Expression Explained&lt;/h3&gt; &lt;p&gt;&lt;font size="2"&gt;In C# 2.0 you can write anonymous delegate methods that helps in reducing the amount of code written. To explain this, first I will demonstrate a simple code snippet that searches for a Contact based on the FirstName field using predicates in C#2.0&lt;/font&gt;&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Contact {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;      &lt;span class="kwrd"&gt;private&lt;/span&gt; String _firstName;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="rem"&gt;/* other fields go here   */&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; String FirstName {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;         get {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt;(_firstName != &lt;span class="kwrd"&gt;null&lt;/span&gt;) {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; _firstName;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;              }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;         set {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;         _firstName = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;          }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;  }&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;&lt;font face="Verdana" color="#000000"&gt;Now lets get all the contacts stored, the GetAllContacts() can also be a call to Data Access Layer to get the values&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;List &amp;lt;Contact&amp;gt; myContacts = GetAllContacts();&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;font size="2"&gt;Next we will use System.Collection.List&amp;lt;T&amp;gt;.FindAll to search for the contact based on FirstName. The MSDN documentation has the following information on the FindAll method&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000080" size="2"&gt;Retrieves the all the elements that match the conditions defined by the specified predicate. &lt;/font&gt;
&lt;p&gt;&lt;font color="#000080" size="2"&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;/font&gt;
&lt;p&gt;&lt;font color="#000080" size="2"&gt;C#&lt;/font&gt;&lt;pre&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;public &lt;/font&gt;&lt;a href="ms-help://ms.vscc.v80/T_System_Collections_Generic_List`1.htm"&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;List&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&amp;lt;T&amp;gt; FindAll (
	&lt;/font&gt;&lt;a href="ms-help://ms.vscc.v80/T_System_Predicate`1.htm"&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;Predicate&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" color="#000080" size="2"&gt;&amp;lt;T&amp;gt; match
)&lt;/font&gt;&lt;/pre&gt;
&lt;h6&gt;&lt;font color="#000080" size="2"&gt;Parameters&lt;/font&gt;&lt;/h6&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;font color="#000080" size="2"&gt;match&lt;/font&gt;
&lt;dd&gt;
&lt;p&gt;&lt;font color="#000080" size="2"&gt;The &lt;/font&gt;&lt;a href="ms-help://ms.vscc.v80/T_System_Predicate`1.htm"&gt;&lt;font color="#000080" size="2"&gt;Predicate&lt;/font&gt;&lt;/a&gt;&lt;font color="#000080" size="2"&gt; delegate that defines the conditions of the elements to search for.&lt;/font&gt;&lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;
&lt;h6&gt;&lt;font color="#000080" size="2"&gt;Return Value&lt;/font&gt;&lt;/h6&gt;
&lt;p&gt;&lt;font color="#000080" size="2"&gt;A &lt;/font&gt;&lt;a href="ms-help://ms.vscc.v80/T_System_Collections_Generic_List`1.htm"&gt;&lt;font color="#000080" size="2"&gt;List&lt;/font&gt;&lt;/a&gt;&lt;font color="#000080" size="2"&gt; containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty &lt;b&gt;List&lt;/b&gt;. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;In our example :&lt;/font&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;List &amp;lt;Contact&amp;gt; contact = myContacts.FindAll( &lt;span class="kwrd"&gt;new&lt;/span&gt; Predicate&amp;lt;Contact&amp;gt; ( FirstNameFilter ) );&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="rem"&gt;//definition for FirstNameFilter&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; FirstNameFilter(Contact c) {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    c.FirstName = &lt;span class="str"&gt;"Bindesh"&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;font size="2"&gt;Lets rewrite the code using C# 2.0 Anonymous method&lt;/font&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;List &amp;lt;Contact&amp;gt; contact = myContacts.FindAll( &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(Contact c) { &lt;span class="kwrd"&gt;return&lt;/span&gt; c.FirstName = &lt;span class="str"&gt;"Bindesh"&lt;/span&gt;} );&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;In the above code we have reduce the step to declare a method named FirstNameFilter through the introduction of anonynmous method. We will still further reduce the code by introducing Lambda expression&lt;/font&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;List &amp;lt;Contact&amp;gt; contact = myContacts.FindAll( c=&amp;gt;c.FirstName == &lt;span class="str"&gt;"Bindesh"&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;div class="csharpcode"&gt;&lt;br&gt;&lt;font face="Verdana"&gt;So basically when when we have a lambda expression defined then we are inherently using delegates. Yes, I do agree that it takes a little while to get accustomed to this syntax, but for a good reason&lt;/font&gt; &lt;img alt="smile_regular" src="http://spaces.live.com/rte/emoticons/smile_regular.gif"&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;A lambda expression is of the format of :&lt;/font&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;(input parameter) =&amp;gt; (statement);  //Called &lt;span class="kwrd"&gt;as&lt;/span&gt; statement lambda&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;(input parameter) =&amp;gt; (expression);  //Called &lt;span class="kwrd"&gt;as&lt;/span&gt; expression lambda&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;div class="csharpcode"&gt;&lt;br&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;The compiler will most of the times be able to infer the type of the input parameter and hence you need not specify one.&lt;/font&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;One important point that I want to mention here is that you can use lamda expression for custom defined delegates, if the lambda expression follows the rule i.e.&lt;/font&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;The lambda expression must contain same no. of parameters as defined in the delegate&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;The types of the parameter must be exactly/implicitly convertible to the corresponding delegate parameter &lt;/font&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="csharpcode"&gt;&lt;font face="Verdana"&gt;The return value of the lambda expression should be of the same type as the one mentioned in the delegate&lt;/font&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;Hope this gives you a basic idea of what is lamda expression and its evolution.&amp;nbsp; In my next blog I will explore more on extension methods, expression trees and queries. &lt;/font&gt;&lt;/p&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;catch you later .. &lt;/font&gt;&lt;/p&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="csharpcode"&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="csharpcode"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;br&gt;&amp;nbsp;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8330899" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="LINQ" scheme="http://blogs.msdn.com/bindeshv/archive/tags/LINQ/default.aspx" /></entry><entry><title>C# 3.0 Features Basics For LINQ - PART 1</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/bindeshv/archive/2008/03/22/c-3-0-features-basics-for-linq-part-1.aspx" /><id>http://blogs.msdn.com/bindeshv/archive/2008/03/22/c-3-0-features-basics-for-linq-part-1.aspx</id><published>2008-03-22T08:51:41Z</published><updated>2008-03-22T08:51:41Z</updated><content type="html">&lt;h3&gt;The 'var' Keyword&lt;/h3&gt; &lt;ol&gt; &lt;li&gt;&lt;font size="2"&gt;Type inferred at compile time&lt;/font&gt;  &lt;li&gt;&lt;font size="2"&gt;Can only be defined within method scope&lt;/font&gt;  &lt;li&gt;&lt;font size="2"&gt;Mostly used when you need a variable for anonymous types which can only be resolved at compile time e.g. LINQ queries&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;Auto Implemented properties&lt;/h3&gt; &lt;p&gt;&lt;font size="2"&gt;This feature eases the creation of properties for a field inside the C# class&amp;nbsp; e.g.&lt;br&gt;&lt;/font&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;//C# 3.0 Code &lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Contact&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Phone { get; set; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;font face="Verdana"&gt;In the above code, we create two properties.T&lt;/font&gt;&lt;font face="Verdana"&gt;he compiler automatically creates a private variable here accessed only via getters and setters. &lt;br&gt;In C# 2.0 we would write a considerably big code for achieving this : &lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;//C# 2.0 Code &lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;Class Contact { &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _name;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; String Name {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    get {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        If(_name != &lt;span class="kwrd"&gt;null&lt;/span&gt; )  {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; _name;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    set {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        _name = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/div&gt;
&lt;h3&gt;Making Sense Of Object Initializers&lt;/h3&gt;
&lt;p&gt;&lt;font size="2"&gt;In C# 3.0 you can use object initializers to assign values to accessible fields/properties at the time of object creation e.g.&lt;/font&gt; 
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;// C# 3.0;Object initializer for our Contact class &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;Contact myContact = &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact { Phone = &lt;span class="str"&gt;'1212'&lt;/span&gt;, Name = &lt;span class="str"&gt;'Bindesh'&lt;/span&gt; }; &lt;/pre&gt;&lt;/div&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;This is useful when we want to use the anonymous types , since the only way to initialize them are using object initializers . It also helps in selecting a portion of the data that is needed from all the available data in an class e.g.&lt;/font&gt;&lt;/p&gt;
&lt;p class="csharpcode"&gt;&lt;font face="Verdana"&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Contact {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FirstName { get; set; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; LastName { get;set;}&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;  Email {get;set;}&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Phone {get;set;}&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;var contact = from c &lt;span class="kwrd"&gt;in&lt;/span&gt; Contacts&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;           select &lt;span class="kwrd"&gt;new&lt;/span&gt; { c.FirstName, c.LastName, c.Email } ;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;h5&gt;Collection Initializers&lt;/h5&gt;
&lt;p&gt;As is the case with object initializers, you can also have the Collections initialized in a short way, like &lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;//C# 3.0;Collections Initializer&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;List &amp;lt;Contact&amp;gt; contacts = &lt;span class="kwrd"&gt;new&lt;/span&gt; List &amp;lt;Contact&amp;gt; { &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;                                            {&lt;span class="str"&gt;'Bindesh'&lt;/span&gt;, &lt;span class="str"&gt;'Vijayan'&lt;/span&gt;},&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;                                            {&lt;span class="str"&gt;'Madhuban'&lt;/span&gt;, &lt;span class="str"&gt;'Singh'&lt;/span&gt;},&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;                                            {&lt;span class="str"&gt;'Sukesh'&lt;/span&gt;, &lt;span class="str"&gt;'A K'&lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;                                         };&lt;/pre&gt;The same would have taken a considerable work in C# 2.0, e.g.&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;List&amp;lt;Contact&amp;gt; contacts = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Contact&amp;gt;();&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="rem"&gt;//call Add each time for adding values&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;contacts.Add( &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact(&lt;span class="str"&gt;'Bindesh'&lt;/span&gt;, &lt;span class="str"&gt;'Vijayan'&lt;/span&gt;));&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;span class="lnum"&gt;&lt;font face="Verdana" color="#000000"&gt;The collection initializer can work for all the types that meets the following criteria :&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="csharpcode"&gt;&lt;span class="lnum"&gt;&lt;font face="Verdana" color="#000000"&gt;Implements IEnumerable interface &lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;li&gt;
&lt;div class="csharpcode"&gt;&lt;span class="lnum"&gt;&lt;font face="Verdana" color="#000000"&gt;Has a public Add() method&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;span class="lnum"&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8330678" width="1" height="1"&gt;</content><author><name>bindeshv</name><uri>http://blogs.msdn.com/members/bindeshv.aspx</uri></author><category term="LINQ" scheme="http://blogs.msdn.com/bindeshv/archive/tags/LINQ/default.aspx" /></entry></feed>