<?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>A Programmer with Microsoft tools &#187; tips and tricks</title>
	<atom:link href="http://msprogrammer.serviciipeweb.ro/category/howto/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://msprogrammer.serviciipeweb.ro</link>
	<description>A programmer journey through code, books and tools</description>
	<lastBuildDate>Mon, 14 May 2012 06:59:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Optimizing EF4 and EDMGen2</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/11/22/optimizing-ef4-and-edmgen2/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/11/22/optimizing-ef4-and-edmgen2/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 05:47:00 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[mini tools list]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[edmgen2]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[Entity framework]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=557</guid>
		<description><![CDATA[Just reading (from Adrian Florea links ) how the EF4 could be optimized : http://www.codeproject.com/KB/database/PerfEntityFramework.aspx
First modification is to “Pre-generated Your View”. For this you must have .ssdl, .csdl, and .msl files – so you change the “Metadata Artifact Processing property to: Copy to Output Directory.”. Then you process the .ssdl, .csdl, and .msl with edmgen [...]]]></description>
			<content:encoded><![CDATA[<p>Just reading (from <a href="http://blogs.ugidotnet.org/adrian/" target="_blank">Adrian Florea</a> links ) how the EF4 could be optimized : <a title="http://www.codeproject.com/KB/database/PerfEntityFramework.aspx" href="http://www.codeproject.com/KB/database/PerfEntityFramework.aspx">http://www.codeproject.com/KB/database/PerfEntityFramework.aspx</a></p>
<p>First modification is to “Pre-generated Your View”. For this you must have <em>.ssdl</em>, <em>.csdl</em>, and <em>.msl</em> files – so you change the “Metadata Artifact Processing property to: Copy to Output Directory.”. Then you process the <em>.ssdl</em>, <em>.csdl</em>, and <em>.msl</em> with edmgen in order to can have the  views.</p>
<p>Until here , all ok.</p>
<p>But, in the next advice, is to keep “Metadata Artifact Processing property to: Embed in Output Assembly.”</p>
<p>One solution is to put “Metadata Artifact Processing property to: Copy to Output Directory.” , compile, put again “Metadata Artifact Processing property to: Embed in Output Assembly.” and compile again. But , if you change the edmx (add fields or tables ) you must redo the operation  &#8211; so you will have more things to do(if you remember)</p>
<p>A solution is to build them on the pre-build step .But how to generate the <em>.ssdl</em>, <em>.csdl</em>, and <em>.msl</em> files  ?</p>
<p>Edmgen2 , <a title="http://code.msdn.microsoft.com/EdmGen2" href="http://code.msdn.microsoft.com/EdmGen2">http://code.msdn.microsoft.com/EdmGen2</a> , to the rescue. Download, put into a lib folder under your solution folder and put a pre-build like this :</p>
<p>$(SolutionDir)lib\edmgen2\edmgen2 /FromEdmx $(ProjectDir)<strong><em>prod</em></strong>.edmx&#8221;</p>
<p>&#8220;%windir%\Microsoft.NET\<strong><em>Framework</em></strong>\v4.0.30319\EdmGen.exe&#8221; /mode:ViewGeneration /language:CSharp /nologo &#8220;/inssdl:<strong><em>prod</em></strong>.ssdl&#8221; &#8220;/incsdl:<strong><em>prod</em></strong>.csdl&#8221;   &#8220;/inmsl:<strong><em>prod</em></strong>.msl&#8221; &#8220;/outviews:$(ProjectDir)<strong><em>prod</em></strong>.Views.cs&#8221;</p>
<p>What you must change on your project?</p>
<p>1. IF you are on 64 bit, change <strong><em>Framework</em></strong> to <strong><em>Framework</em></strong>64</p>
<p>2. change the <strong><em>prod</em></strong> with your edmx name.</p>
<p>What is the performance?</p>
<p>Tested by loading a table with 301 rows by doing the steps :</p>
<p>1. open connection, load all table in objects(POCO), closing connection</p>
<p>2. open connection , find object with PK = 1, closing connection</p>
<p>3. open connection ,  loading 1 tables with 2 related (include ) , closing connection</p>
<p>The results are in milliseconds:</p>
<p><strong>Without</strong> pre-compiled views</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="111">LoadTable</td>
<td width="97">LoadID</td>
<td width="132">LoadMultiple</td>
<td width="64">Total Time</td>
</tr>
<tr>
<td>579</td>
<td>800</td>
<td>172</td>
<td>1551</td>
</tr>
<tr>
<td>563</td>
<td>755</td>
<td>171</td>
<td>1489</td>
</tr>
<tr>
<td>559</td>
<td>754</td>
<td>169</td>
<td>1482</td>
</tr>
<tr>
<td>568</td>
<td>762</td>
<td>240</td>
<td>1570</td>
</tr>
</tbody>
</table>
<p><strong>With</strong> pre-compiled views:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="111">LoadTable</td>
<td width="97">LoadID</td>
<td width="132">LoadMultiple</td>
<td width="64">Total Time</td>
</tr>
<tr>
<td>606</td>
<td>807</td>
<td>183</td>
<td>1596</td>
</tr>
<tr>
<td>509</td>
<td>706</td>
<td>177</td>
<td>1392</td>
</tr>
<tr>
<td>852</td>
<td>137</td>
<td>192</td>
<td>1181</td>
</tr>
<tr>
<td>530</td>
<td>733</td>
<td>221</td>
<td>1484</td>
</tr>
<tr>
<td>523</td>
<td>722</td>
<td>183</td>
<td>1428</td>
</tr>
</tbody>
</table>
<p>The average / min / max results:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="111"></td>
<td width="97">average</td>
<td width="132">max</td>
<td width="64">min</td>
</tr>
<tr>
<td>without</td>
<td>1523</td>
<td>1570</td>
<td>1482</td>
</tr>
<tr>
<td>with</td>
<td>1413.25</td>
<td>1596</td>
<td>1181</td>
</tr>
</tbody>
</table>
<p>In the next picture the smaller the duration(milliseconds), is the better :</p>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/11/image2.png"><img style="display: inline; border: 0px;" title="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/11/image_thumb2.png" border="0" alt="image" width="587" height="260" /></a></p>
<p>Conclusions:</p>
<p>1.  For the average and min the difference is 7%, respectively 20%. Please remember we are using only 3 queries.</p>
<p>For the max, it is vey curious : the with is more than without. The penalty is 1%, I think that is a measuring error ? – or maybe not. However , the penalty is small comparing with others.</p>
<p>2. Very curious, find after ID, with a table with 301 rows, took longer than loading the whole table.However, did not take into accound finding in the list the object( it is in memory also)</p>
<p>3. It may worth to add the pre-build step shown before to pre-compile views.</p>
<p>Links :</p>
<p><a title="http://www.codeproject.com/KB/database/PerfEntityFramework.aspx" href="http://www.codeproject.com/KB/database/PerfEntityFramework.aspx">http://www.codeproject.com/KB/database/PerfEntityFramework.aspx</a></p>
<p><a title="http://msdn.microsoft.com/en-us/library/bb896240.aspx" href="http://msdn.microsoft.com/en-us/library/bb896240.aspx">http://msdn.microsoft.com/en-us/library/bb896240.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/11/22/optimizing-ef4-and-edmgen2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five common mistakes for ASP.NET (MVC) accesing resources : css, js, images, ajax</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/10/09/five-common-mistakes-for-asp-net-mvc-accesing-resources-css-js-images-ajax/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/10/09/five-common-mistakes-for-asp-net-mvc-accesing-resources-css-js-images-ajax/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 14:00:54 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[common mistakes]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=451</guid>
		<description><![CDATA[To have once for all the link to show to people, because too much makes the same error again and again.
(From here  &#8211; you can use ResolveUrl or  Url.Content &#8211; it&#8217;s the same for me. I use ResolveUrl because I used first &#8230;)
Case 1 The image does not display
Please check you have the [...]]]></description>
			<content:encoded><![CDATA[<p>To have once for all the link to show to people, because too much makes the same error again and again.</p>
<p>(From here  &#8211; you can use ResolveUrl or  Url.Content &#8211; it&#8217;s the same for me. I use ResolveUrl because I used first &#8230;)</p>
<h3><em><strong>Case 1</strong></em> The image does not display</h3>
<p>Please check you have the following :</p>
<pre class="brush: jscript;">
&lt;img src='&lt;%= ResolveUrl(&quot;~/Content/images/YOURIMAGE.jpg&quot; )%&gt;'  alt=&quot;image&quot; style=&quot;border:0&quot; /&gt;
</pre>
<h3>Case 2 The css does not show</h3>
<p>Please check you have the following :</p>
<pre class="brush: csharp;">
&lt;%= string.Format(&quot;&lt;link href='{0}' type='text/css' rel='stylesheet' /&gt;&quot;, ResolveUrl(&quot;~/Content/your.css&quot;)) %&gt;
</pre>
<p>or</p>
<pre class="brush: jscript;">
&lt;style type=&quot;text/css&quot;&gt;
@import '&lt;%= ResolveUrl(&quot;~/Content/your.css&quot;) %&gt;';

&lt;/style&gt;
</pre>
<h3>Case 3 The js does not execute (undefined error)</h3>
<p>Please check you have the following :</p>
<pre class="brush: jscript;">
&lt;script type=&quot;text/javascript&quot; src='&lt;%= ResolveUrl(&quot;~/Scripts/yourjs.js&quot;)%&gt;'&gt;&lt;/script&gt;
</pre>
<h3>Case 4 The js does execute in aspx page, but did not execute under js file</h3>
<p>Please check you DO NOT have the following</p>
<p>&lt;%</p>
<p>in the js file. The js file is not interpreted by the same engine as aspx, so can not interpret asp.net tags. Instead , add a parameter to your function : the path.</p>
<p>Simple example  : Let’s say in aspx you have :</p>
<pre class="brush: jscript;">
&lt;script type=”text/javascript”&gt;

function Generate(){

window.open(‘&lt;% Url.Action(“About”)%&gt;’);
}

&lt;/script&gt;
</pre>
<p>and you call Generate();</p>
<p>When you put in .js file, please put this :</p>
<pre class="brush: jscript;">
function Generate(url){

window.open(url);
}
</pre>
<p>and call like this :</p>
<pre class="brush: jscript;">
Generate('&lt;% Url.Action(“About”)%&gt;');
</pre>
<h3>Case 5 The ajax request gives you a 404 error.</h3>
<p>Please ensure that you have</p>
<pre class="brush: csharp;">
&lt;%= ResolveUrl(&quot;~/path”)%&gt;
</pre>
<p>and not</p>
<p>/path</p>
<h3>Bonus 1: T4MVC , http://mvccontrib.codeplex.com/releases</h3>
<h3>Bonus 2: Edit the project file and put &lt;MvcBuildViews&gt;true&lt;/MvcBuildViews&gt;</h3>
<p>( short url: http://bit.ly/asp5Mistakes)</p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/10/09/five-common-mistakes-for-asp-net-mvc-accesing-resources-css-js-images-ajax/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Generating history trigger with EF , edmx and TT files</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/09/27/generating-history-trigger-with-ef-edmx-and-tt-files/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/09/27/generating-history-trigger-with-ef-edmx-and-tt-files/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 04:38:49 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[.tt]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[EF]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=440</guid>
		<description><![CDATA[I have wrote in an older post ( http://msprogrammer.serviciipeweb.ro/2010/06/28/ef-automatic-history-of-table-and-t4-files-tt-files/ ) how to generate history code for tables . The easy solution was to create a tt file that track for the ObjectContext the SaveChanges for each table that has a “history” in name. the limitation is that , when you raise an sql command such [...]]]></description>
			<content:encoded><![CDATA[<p>I have wrote in an older post ( <a title="http://msprogrammer.serviciipeweb.ro/2010/06/28/ef-automatic-history-of-table-and-t4-files-tt-files/" href="http://msprogrammer.serviciipeweb.ro/2010/06/28/ef-automatic-history-of-table-and-t4-files-tt-files/">http://msprogrammer.serviciipeweb.ro/2010/06/28/ef-automatic-history-of-table-and-t4-files-tt-files/</a> ) how to generate history code for tables . The easy solution was to create a tt file that track for the ObjectContext the SaveChanges for each table that has a “history” in name. the limitation is that , when you raise an sql command such as &#8220;update table &#8221; you must load from database a lot of rows for this&#8230;.</p>
<p>Now I want to show the same thing, but generating triggers in database for that ! I start also from edmx file and with a template stealed from <a title="http://forums.asp.net/p/1599616/4083198.aspx" href="http://forums.asp.net/p/1599616/4083198.aspx">http://forums.asp.net/p/1599616/4083198.aspx</a> ( to have type of fields in the database ) and another stealed and modified from StackOverflow(to generate trigger for after insert , update, delete) I manage to have a solution to generate sql tables and trigger code.</p>
<p>When is that good ?At the beginning stages of a project when the table structure changes by adding a new parameter.</p>
<p>Sample code generated for table Notes(ID, TextNote, PersonID)</p>
<pre class="brush: sql;">
print 'Create table Notes_History ';
Create Table Notes_History(
		ID_Notes_History BIGINT IDENTITY NOT NULL
		,History_Action varchar(50)
		,History_From varchar(100) default HOST_NAME()
		,History_User varchar(50) default SYSTEM_USER
		,History_Date varchar(50) default  getdate()
	   ,Id  int   NOT NULL
	   ,Textnote  nvarchar (255)  NULL
	   ,PersonId  int   NULL
	)
print 'end Create table Notes_History ';
GO
print 'create trigger for Notes'
GO
CREATE TRIGGER dbo.TR_IUP_Notes
   ON  Notes
   AFTER INSERT, UPDATE, DELETE
AS
BEGIN
    SET NOCOUNT ON;
	DECLARE @Ins int

DECLARE @Del int

SELECT @Ins = Count(*) FROM inserted

SELECT @Del = Count(*) FROM deleted
if(@Ins  + @Del = 0)
	return;

declare @operation varchar(50)
	set @operation ='update';
	if(@ins &lt; @del)
		set @operation ='delete';
	if(@ins &gt; @del)
		set @operation ='insert';

	if(@ins &lt;= @del)
	begin
		INSERT INTO Notes_History(History_Action ,Id,Textnote,PersonId)
			select @operation ,Id,Textnote,PersonId from deleted
	end
    else
	begin
    INSERT INTO Notes_History(History_Action ,Id,Textnote,PersonId)
			select @operation ,Id,Textnote,PersonId from inserted
	end
END
</pre>
<p>The drawback of the code : the user that executes is not always the logged sql server user&#8230;<br />
Anyway, what  you have to do to use this automatically generated history/audit for tables ?</p>
<p>download <a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/09/historysql.zip">historysql</a> and modify</p>
<p>string inputFile = @&#8221;Model1.edmx&#8221;;</p>
<p>from historysql.tt to your edmx name. Then take the generated code and execute in sql server.</p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/09/27/generating-history-trigger-with-ef-edmx-and-tt-files/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>First Install of tools for programmer</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/09/06/first-install-of-tools-for-programmer/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/09/06/first-install-of-tools-for-programmer/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 04:05:00 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=418</guid>
		<description><![CDATA[My primary tools are Visual Studio ( and the Express suite) , Sql Server ( and SQL Server Management Studio )( and the Express suite) and Office (Excel, Word)
Those are the modification that I do every time … I wish there were enabled by default :
For VS2010 
Go to=&#62; Tools, Options , Html, Formatting ,Check [...]]]></description>
			<content:encoded><![CDATA[<p>My primary tools are Visual Studio ( and the Express suite) , Sql Server ( and SQL Server Management Studio )( and the Express suite) and Office (Excel, Word)</p>
<p>Those are the modification that I do every time … I wish there were enabled by default :</p>
<p><strong>For VS2010 </strong></p>
<blockquote><p>Go to=&gt; Tools, Options , Html, Formatting ,Check “ Insert attribute value quotes when typing”</p></blockquote>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image.png"><img style="display: inline; border: 0px;" title="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image_thumb.png" border="0" alt="image" width="548" height="326" /></a></p>
<p>This saves me a lot of time , when I put : input type=”text” , the “  are inserted automatically.</p>
<p><strong>For SSMS</strong></p>
<blockquote><p>Go to=&gt; Tools, Options , Designers , uncheck “Prevent saving changes that require table re-creation”</p>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image_3.png"><img style="display: inline; border: 0px;" title="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image_thumb_3.png" border="0" alt="image" width="486" height="289" /></a></p></blockquote>
<p>As a developer, I do modify tables … and this wont let me the first time …</p>
<p><strong>For Excel, Word</strong></p>
<blockquote><p>Alt+F11 (Visual Basic Editor), Tools, Options, Editor Tab, uncheck “Auto syntax check”, check “require variable declaration”</p>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image_4.png"><img style="display: inline; border: 0px;" title="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/FirstInstalloftoolsforprogrammer_14626/image_thumb_4.png" border="0" alt="image" width="431" height="376" /></a></p></blockquote>
<p>“require variable declaration”  :This saves you a lot of time debugging or writing “Option Explicit” .</p>
<p>“Auto syntax check “ : I do not want a message box each time I do an error. The error is seen in red … no need for a Msgbox.</p>
<p>How about you, dear reader ? Do you have programs that require after installation modifying of options ?</p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/09/06/first-install-of-tools-for-programmer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Extensions Methods</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/03/22/asp-net-mvc-extensions-methods/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/03/22/asp-net-mvc-extensions-methods/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 05:44:00 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[method extensions]]></category>
		<category><![CDATA[select list]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=79</guid>
		<description><![CDATA[These are my extensions.

Not display dropdownlist if the Select list is null

public static MvcHtmlString DropDownListNull(this HtmlHelper html, string Name, SelectList select, object htmlAttributes)
{

if (select == null)
return MvcHtmlString.Empty;
else
 return html.DropDownList(Name, select, htmlAttributes);

}


Transform Enum to SelectList

#region enum to list
        private static List&#60;KeyValuePair&#60;long, string&#62;&#62; FromEnum(this Type e)
     [...]]]></description>
			<content:encoded><![CDATA[<p>These are my extensions.</p>
<ol>
<li>Not display dropdownlist if the Select list is null
<pre class="brush: csharp;">
public static MvcHtmlString DropDownListNull(this HtmlHelper html, string Name, SelectList select, object htmlAttributes)
{

if (select == null)
return MvcHtmlString.Empty;
else
 return html.DropDownList(Name, select, htmlAttributes);

}
</pre>
</li>
<li>Transform Enum to SelectList
<pre class="brush: csharp;">
#region enum to list
        private static List&lt;KeyValuePair&lt;long, string&gt;&gt; FromEnum(this Type e)
        {
            List&lt;KeyValuePair&lt;long, string&gt;&gt; kvp = new List&lt;KeyValuePair&lt;long, string&gt;&gt;();
            foreach (var s in Enum.GetValues(e))
            {
                kvp.Add(new KeyValuePair&lt;long, string&gt;((int)s, s.ToString()));
            }
            return kvp;
        }
        public static SelectList ToSelectList(this Type enumObj)
        {

            return new SelectList(enumObj.FromEnum(), &quot;Key&quot;, &quot;Value&quot;);

        }
        #endregion
</pre>
</li>
<li>Transform Generic list into a SelectList
<pre class="brush: csharp;">
              #region Generic List to SelectItem
        public static SelectList SelectFromList&lt;TItem&gt;(this List&lt;TItem&gt; values,
            Expression&lt;Func&lt;TItem, string&gt;&gt; key, Expression&lt;Func&lt;TItem, string&gt;&gt; value)
        {
            var Key = key.Compile();
            var Value = value.Compile();
            List&lt;KeyValuePair&lt;string, string&gt;&gt; kvp = new List&lt;KeyValuePair&lt;string, string&gt;&gt;(values.Count);
            values.ForEach(item =&gt;
                kvp.Add(new KeyValuePair&lt;string, string&gt;(Key.Invoke(item), Value.Invoke(item))));

            return new SelectList(kvp, &quot;Key&quot;, &quot;Value&quot;);

        }
        #endregion
</pre>
</li>
<li> Display pager control
<pre class="brush: csharp;">
#region paged list control
        //after http://geekswithblogs.net/nuri/archive/2009/08/05/mvc-paged-list.aspx
        /// &lt;summary&gt;
        /// Shows a pager control - Creates a list of links that jump to each page
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;page&quot;&gt;The ViewPage instance this method executes on.&lt;/param&gt;
        /// &lt;param name=&quot;pagedList&quot;&gt;A PagedList instance containing the data for the paged control&lt;/param&gt;
        /// &lt;param name=&quot;controllerName&quot;&gt;Name of the controller.&lt;/param&gt;
        /// &lt;param name=&quot;actionName&quot;&gt;Name of the action on the controller.&lt;/param&gt;
        public static void ShowPagerControl(this ViewPage page, BasePagedListImplementation pagedList, string formatUrl)
        {
            HtmlTextWriter writer = new HtmlTextWriter(page.Response.Output);
            if (writer != null)
            {
                for (int pageNum = 1; pageNum &lt;= pagedList.PageCount; pageNum++)
                {
                    bool samepage=(pageNum == pagedList.PageNumber);
                    if (!samepage)
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Href,string.Format(formatUrl, pageNum));
                        writer.AddAttribute(HtmlTextWriterAttribute.Alt, &quot;Page &quot; + pageNum);
                        writer.RenderBeginTag(HtmlTextWriterTag.A);
                    }

                    writer.AddAttribute(HtmlTextWriterAttribute.Class,
                                        pageNum == pagedList.PageNumber ?
                                                            &quot;pageLinkCurrent&quot; :
                                                            &quot;pageLink&quot;);

                    writer.RenderBeginTag(HtmlTextWriterTag.Span);
                    writer.Write(pageNum);
                    writer.RenderEndTag();

                    if (!samepage)
                    {
                        writer.RenderEndTag();
                    }
                    writer.Write(&quot;&amp;nbsp;&quot;);
                }

                writer.Write(&quot;(&quot;);
                writer.Write(pagedList.TotalItemCount);
                writer.Write(&quot; items in all)&quot;);
            }
        }

        #endregion
</pre>
</li>
</ol>
<p>Other extensions available that are good :</p>
<ol>
<li><a href="http://blog.wekeroad.com/blog/asp-net-mvc-list-helper-extension-method/" target="_blank">http://blog.wekeroad.com/blog/asp-net-mvc-list-helper-extension-method/</a></li>
<li><a href="http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx" target="_blank">http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx</a></li>
<li><a href="http://helios.ca/2009/09/21/asp-net-mvc-extension-methods-of-urlhelper/">http://helios.ca/2009/09/21/asp-net-mvc-extension-methods-of-urlhelper/</a></li>
<li><a href="http://blog.donnfelker.com/2010/02/25/asp-net-mvc-tempdata-extension-methods/">http://blog.donnfelker.com/2010/02/25/asp-net-mvc-tempdata-extension-methods/</a></li>
<li><a href="http://inq.me/post/ASPNet-MVC-Extension-method-to-create-a-Security-Aware-HtmlActionLink.aspx">http://inq.me/post/ASPNet-MVC-Extension-method-to-create-a-Security-Aware-HtmlActionLink.aspx</a></li>
</ol>
<p>If you know more, please tell me</p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/03/22/asp-net-mvc-extensions-methods/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How To &#8230; Create a new site similar with regular internet site in Windows 7</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/01/24/how-to-create-a-new-site-similar-with-regular-internet-site-in-windows-7/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/01/24/how-to-create-a-new-site-similar-with-regular-internet-site-in-windows-7/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 01:00:50 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[You tube]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/msprogrammer/index.php/how-to-create-a-new-site-similar-with-regular-internet-site-in-windows-7/</guid>
		<description><![CDATA[&#160;
Step 1 : Make a Web site with Visual Studio
Step 2 : In IIS Manager create the new site
Step 3: edit the hosts file (administrative rights)
Step 4: Create the Web application, modify his Project=&#62;properties=&#62;Web =&#62;Use local IIS Web Server
Step 5: Edit bindings for new site to point to the folder of application
Step 6: Run Visual [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>Step 1 : Make a Web site with Visual Studio</p>
<p>Step 2 : In IIS Manager create the new site</p>
<p>Step 3: edit the hosts file (administrative rights)</p>
<p>Step 4: Create the Web application, modify his Project=&gt;properties=&gt;Web =&gt;Use local IIS Web Server</p>
<p>Step 5: Edit bindings for new site to point to the folder of application</p>
<p>Step 6: Run Visual Studio</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:7abcae84-97e9-4764-a3f2-d3f1563bc6fe" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/7T_Qd93iNXk&amp;hl=en"></param><embed src="http://www.youtube.com/v/7T_Qd93iNXk&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/01/24/how-to-create-a-new-site-similar-with-regular-internet-site-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to &#8211; transmit data between Windows Forms</title>
		<link>http://msprogrammer.serviciipeweb.ro/2009/12/30/how-to-transmit-data-between-windows-forms/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2009/12/30/how-to-transmit-data-between-windows-forms/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 00:27:06 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[You tube]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[send data]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/msprogrammer/index.php/how-to-transmit-data-between-windows-forms/</guid>
		<description><![CDATA[&#160;
You can download the project from

 here

Also you can look to the video :



&#160;
Very Short: 

Make a constructor on the form that has a parameter of the type you want to send. 
Do not forget the call to this( in order to execute InitializeComponent). 
Always verify on Load event that the copy of parameter is [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>You can download the project from</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:a8659082-d4c9-4266-b16f-2dc7bfc0f082" class="wlWriterEditableSmartContent">
<p> <a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2009/12/transmitparameters.zip" target="_blank">here</a></p>
</div>
<p>Also you can look to the video :</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:29ee9052-cdcd-4fac-81b2-7f6023e0ba3f" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/iCXzkNSLk8E&amp;hl=en"></param><embed src="http://www.youtube.com/v/iCXzkNSLk8E&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
</div>
<p>&#160;</p>
<p>Very Short: </p>
<ol>
<li>Make a constructor on the form that has a parameter of the type you want to send. </li>
<li>Do not forget the call to this( in order to execute InitializeComponent). </li>
<li>Always verify on Load event that the copy of parameter is initialized.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2009/12/30/how-to-transmit-data-between-windows-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

