<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dot Net Thoughts &#187; ASP.Net MVC</title>
	<atom:link href="http://www.dotnetthoughts.net/category/net/asp-net-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to use Stored Procedures in Entity Framework</title>
		<link>http://www.dotnetthoughts.net/2010/07/08/how-to-use-stored-procedures-in-entity-framework/</link>
		<comments>http://www.dotnetthoughts.net/2010/07/08/how-to-use-stored-procedures-in-entity-framework/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 10:34:33 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Entity Framewrok]]></category>
		<category><![CDATA[SP]]></category>
		<category><![CDATA[Stored Procedure]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=976</guid>
		<description><![CDATA[In the current project we are using Entity Framework for database operations. Entity Framework comes with Visual Studio SP1, which helps you to map tables / views / procedures as entities in C# / VB Code. You can find more details about EF from here : http://msdn.microsoft.com/en-us/library/bb399572.aspx. In this post I am explaining how to [...]]]></description>
			<content:encoded><![CDATA[<p>In the current project we are using Entity Framework for database operations. Entity Framework comes with Visual Studio SP1, which helps you to map tables / views / procedures as entities in C# / VB Code. You can find more details about EF from here : <a title="Entity Framework Overview" href="http://msdn.microsoft.com/en-us/library/bb399572.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb399572.aspx</a>. In this post I am explaining how to use Stored Procedures in Entity Framework.</p>
<ol>
<li>Add the Stored Procedure to the Entity Model Designer using Update Model From Database Option.</li>
<div id="attachment_979" class="wp-caption aligncenter" style="width: 546px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Add_Procedure.png"><img class="size-full wp-image-979" title="Add Procedure" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Add_Procedure.png" alt="Add Procedure" width="536" height="485" /></a><p class="wp-caption-text">Add Procedure</p></div>
<li>If you are added successfully, you can get the procedure in Model Browser.</li>
<div id="attachment_981" class="wp-caption aligncenter" style="width: 299px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Model_Browser.png"><img class="size-full wp-image-981" title="Model Browser " src="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Model_Browser.png" alt="Model Browser " width="289" height="341" /></a><p class="wp-caption-text">Model Browser </p></div>
<li>Right click on the Procedure name and select Create Function Import.</li>
<div id="attachment_980" class="wp-caption aligncenter" style="width: 308px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/create_fn_import.png"><img class="size-full wp-image-980" title="Create Function Import" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/create_fn_import.png" alt="Create Function Import" width="298" height="320" /></a><p class="wp-caption-text">Create Function Import</p></div>
<li>It will popups a Windows with Stored Procedure Name, Function Import Name and Return Type. If the procedure returns nothing, you can choose none. If the procedure is returns single value, like UserId, Number Of Rows etc, then you can choose scalar option, where you need to specify the return type. And if the procedure is returns Table or Number of Rows, you need to choose the last option Entities, which will allow to select entities created in the Model as the Output. Sometimes we need to create a View in the DB and need to import it in the Model, so that we can use the View as the return type entity.  Select the appropriate return type and click Ok. You can use this in code. In this code I am using a View to return the selected users.</li>
</ol>
<div id="attachment_978" class="wp-caption aligncenter" style="width: 399px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Add_Function_Import.png"><img class="size-full wp-image-978" title="Add Function Import dialog" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/07/Add_Function_Import.png" alt="Add Function Import dialog" width="389" height="278" /></a><p class="wp-caption-text">Add Function Import dialog</p></div>
<pre class="brush: csharp;">

using (SampleEntities context = new SampleEntities())
{
/*
* Thanks to Barry Soetoro.
* I was not calling the GetAllUsers function.
List&lt;Users&gt; Users = null;
Users = (from user in context.Users
             select user).ToList();
this.dataGridView1.DataSource = Users;
*/
//Updated Version.
IEnumerable&lt;UsersView&gt; userview = context.GetAllUsers();
this.dataGridView1.DataSource = userview;
}
</pre>
<p>This will display list of Users in the DataGridView. Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/07/08/how-to-use-stored-procedures-in-entity-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Captcha HTML Helper</title>
		<link>http://www.dotnetthoughts.net/2009/09/15/creating-captcha-html-helper/</link>
		<comments>http://www.dotnetthoughts.net/2009/09/15/creating-captcha-html-helper/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 09:49:13 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Captcha]]></category>
		<category><![CDATA[Captcha HTML Helper]]></category>
		<category><![CDATA[Custom HTML Helper]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=389</guid>
		<description><![CDATA[After working with ASP.Net MVC, and my previous posts, in this Post I am trying to implement a Captcha HTML Helper, an HTML Helper is just a method that returns a string. Creating Custom HTML Helpers. It is an extension method, to the existing HTML Helper class. Here is code.(For more details about the Captcha [...]]]></description>
			<content:encoded><![CDATA[<p>After working with ASP.Net MVC, and my previous posts, in this Post I am trying to implement a Captcha HTML Helper, an HTML Helper is just a method that returns a string. <a href="http://www.asp.net/learn/mvc/tutorial-09-cs.aspx" target="_blank">Creating Custom HTML Helpers</a>. It is an extension method, to the existing HTML Helper class.<br />
Here is code.(For more details about the Captcha generation code, check my previous post. : <a href="http://anuraj.wordpress.com/2009/09/15/captcha-using-asp-net-and-c/">Captcha using ASP.Net and C#</a>);</p>
<pre class="brush: csharp;">
 public static class CaptchaHelper
    {
        public static string Captcha(this HtmlHelper helper, string text)
        {
            string srcPath = System.Web.VirtualPathUtility.ToAbsolute(&quot;~/Handler1.ashx&quot;);
            string htmlContent = string.Empty;
            htmlContent += &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;function __rc(){document.getElementById(\&quot;&quot; + text +
                           &quot;\&quot;).src = \&quot;../Handler1.ashx?query=\&quot; + Math.random();}&lt;/script&gt;&quot;;
            htmlContent += string.Format(&quot;&lt;img id=\&quot;{0}\&quot; src=\&quot;{1}\&quot; alt=\&quot;Captcha Image\&quot;/&gt;&quot;, text, srcPath);
            htmlContent += &quot;&lt;a href=\&quot;#\&quot; onclick=\&quot;javascript:__rc();\&quot;&gt;Reset&lt;/a&gt;&quot;;
            return htmlContent;
        }
    }
</pre>
<p>And in the View you can use like, you may need to import the Namespace of CaptchaHelper class.</p>
<pre class="brush: xml;">
 &lt; %= Html.Captcha(&quot;Sample&quot;) %&gt;
</pre>
<p>It will render a security image. Happy Programming</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/09/15/creating-captcha-html-helper/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
