<?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>blog.dervalp.com</title>
	<atom:link href="http://blog.dervalp.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dervalp.com</link>
	<description>Think before Programming (Public learning)</description>
	<lastBuildDate>Sat, 20 Mar 2010 22:22:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unity Application Block</title>
		<link>http://blog.dervalp.com/2009/10/20/unity-application-block/</link>
		<comments>http://blog.dervalp.com/2009/10/20/unity-application-block/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 11:51:57 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=382</guid>
		<description><![CDATA[I know It&#8217;s a shame, but I did not know Unity Application Block. I was searching for an IOC/Depedency Injection and a colleage advised me to learn Unity. If like me, you did not know the existence of Unity (developed by Microsoft), let&#8217;s take a look on Unity&#8217;s Codeplex website. They are some nice screencasts [...]]]></description>
			<content:encoded><![CDATA[<p>I know It&#8217;s a shame, but I did not know Unity Application Block. I was searching for an IOC/Depedency Injection and a colleage advised me to learn Unity. If like me, you did not know the existence of Unity (developed by Microsoft), let&#8217;s take a look on <a href="http://www.codeplex.com/unity/">Unity&#8217;s Codeplex website</a>. They are some nice screencasts and a good doc on mdsn.</p>
<p>And you, what do you think about Unity ?</p>
<p>Note : I am also currently learning PRISM V.2, that&#8217;s a very interesting topic. PRISM uses Unity and it is why it&#8217;s important to understand how it works.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d382').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d382" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;title=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;title=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/10/20/unity-application-block/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;title=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;title=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;title=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Unity+Application+Block+@+http://blog.dervalp.com/2009/10/20/unity-application-block/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/10/20/unity-application-block/&amp;t=Unity+Application+Block" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d382').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d382').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/10/20/unity-application-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC C# Linq to Stored procedure with Dynamic Query (a quick phone book, piece of Cake !)</title>
		<link>http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/</link>
		<comments>http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 18:53:02 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=330</guid>
		<description><![CDATA[Salut les Gars !
I am back with a little code I wrote today for my business. I had to create a little phone book.
The db I had to query was pretty complicated and I did not want to create all the stuff you need for an effective Linq ot Sql classes. Therefore, I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>Salut les Gars !</p>
<p>I am back with a little code I wrote today for my business. I had to create a little phone book.</p>
<p>The db I had to query was pretty complicated and I did not want to create all the stuff you need for an effective Linq ot Sql classes. Therefore, I decided to use a stored procedure who retrieve all the users (about 5000) with all the information I need. This application will be a one-shot application and  his time life will be about 1 or 2 years. Also, the release date is very tight.</p>
<h2><span id="more-330"></span></h2>
<h2>Step 1 : Create the stored procedure :</h2>
<p>I am not going to teach you how to create one. All you need to know is the result of the query. My stored prod will return a row with the Email column, the city, the office address,&#8230;</p>
<p>Here, an example of a stored prod you might deal with :</p>
<pre class="brush: c;">

SELECT uEmail, Offices.ofPostalCode , uTelExtension, uMobilePhone, uDefaultLang,
Offices.ofTelephone, ofFax, rsName.value, rsCity.value as 'City', rsAdd.value as 'Address', rsAddSuite.value as 'Suite',
(Select Resources.value
FROM States
join Resources ON Resources.rsID = States.rsStName AND Resources.loID = Users.uDefaultLang
WHERE States.stID = Offices.stID) as 'State/Province',
(Select Resources.value
FROM Countries
join Resources ON Resources.rsID = Countries.rsCnName AND Resources.loID = Users.uDefaultLang
WHERE Countries.cnID = Offices.cnID) as 'Country'
FROM Users
join Offices ON Users.ofID = Offices.ofID
join Resources AS rsName ON rsName.rsID = Offices.rsOfName AND rsName.loID = Users.uDefaultLang
join Resources AS rsCity ON rsCity.rsID = Offices.rsOfCity AND rsCity.loID = Users.uDefaultLang
join Resources AS rsAdd ON rsAdd.rsID = Offices.rsOfAddress AND rsAdd.loID = Users.uDefaultLang
join Resources AS rsAddSuite ON rsAddSuite.rsID = Offices.rsOfAddressSuite AND rsAddSuite.loID = Users.uDefaultLang
join States ON States.stID = Offices.stID
join Countries ON Countries.cnID = Offices.cnID
WHERE uTelExtension != ''
</pre>
<p>I know, there is no parameter in the stored prod but we could add some later (the language for example).</p>
<h2>Step 2 : Add the Stored Procedure in a Sql to Linq Class :</h2>
<p>Create an Linq to Sql class to you solution or use one you already have. Open you Server Explorer, add a connection to the db you want simply drag and drop the stored procedure in the dbml.</p>
<p><img class="alignnone size-full wp-image-335" title="linqtostoredprod" src="http://blog.dervalp.com/wp-content/uploads/2009/06/linqtostoredprod.png" alt="linqtostoredprod" width="1143" height="648" /></p>
<h2>Step 3 : Create your pseudo Factory :</h2>
<p>So I added this in a SqlUserRepository class which I will use in my controller to retrieve data and filter it.</p>
<pre class="brush: c;">

public IEnumerable&lt;UserDB&gt; getUserFromDb()

{

LinqToUsersDataContext db = new LinqToUsersDataContext();

var res = from Users in db.spUserGetUserDB()

select new UserDB()

{

Email = Users.uEmail,

Address = Users.Address,

City = Users.City,

Country = Users.Country,

StateProvince = Users.State_Province,

MobilePhone = Users.uMobilePhone,

ofTelephone = Users.ofTelephone,

Suite = Users.Suite,

TexExtension = Users.uTelExtension

};
return res.AsEnumerable();
}
</pre>
<h2>Step 4 : Create Filter :</h2>
<p>For this example, I will create two filters, one which will filter by Email and the other which will filter by City Name. Note that we do not speak here about best design and performance. We want something quickly. I guess when you read the stored prod, you said &#8220;Oh what for a crap&#8221;, yes I know but it was an old db with bad design and I must deal with&#8230;</p>
<p>Back to our Filters, the magic word here is &#8220;this&#8221;. You create a static class with an Ubiquitous Language (DDD style, traduction explicit name) and you create some static methods. In this example, it is &#8220;this IQueryable&lt;UserDB&gt;&#8221; and if you play with an object of that type, the intellisense will detect automatically and will show it to you (Like we saw in a previous post, <a href="http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/" target="_blank">here</a>).</p>
<pre class="brush: text;">

public static class UserDBFilter
{
public static IQueryable&lt;UserDB&gt; LikeEmail(this IQueryable&lt;UserDB&gt; qry, string Email )
{
return from user in qry where user.Email.Contains(Email) select user;

}

public static IQueryable&lt;UserDB&gt; WithCity(this IQueryable&lt;UserDB&gt; qry, string City)
{
return from user in qry where user.City == City select user;

}
}
</pre>
<h2>Step 5 : Create the dynamic query :</h2>
<p>To test if everything works fine, I created a little integration test.</p>
<pre class="brush: c;">

[TestMethod]
public void GetRetrieveUserFromDbwithparam()
{
string email;
string city;

email = &quot;pierre@dervalp.com&quot;;
city = &quot;Tokyo&quot;;
var res = _service.getUserFromDb().AsQueryable();

if (!string.IsNullOrEmpty(email))
res = res.LikeEmail(email);

if (!string.IsNullOrEmpty(city))
res = res.WithCity(city);

Assert.IsNull(res);

}
</pre>
<p>It tried to put the string email to null, after the sting city to null, after both. In every case I receive what I wanted to have.</p>
<h2>Step 6 : Create the controller and the view:</h2>
<p>We create a basic controller and add a function ListUsers(). Per default, we render all the users (for example).</p>
<pre class="brush: c;">

private readonly SqlRepositoryService _dbService;
//CTOR (instantiate the service you need)
public MergeController()
{
_dbService = new SqlRepositoryService();
}

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult ListUsers()
{
// PagedList&lt;UserDB&gt; userlist = new PagedList&lt;UserDB&gt;(_dbService.getUserFromDb().ToList(),0, 5);

IList&lt;UserDB&gt; userlist = new List&lt;UserDB&gt;(_dbService.getUserFromDb());
return View(userlist);
}
</pre>
<p>Right-click on ListUsers() and create a strong typely-type view List. If you run the application, you will receive all the user in a List.</p>
<p>I cannot show you the result (private information inside).</p>
<h2>Step 7 : Add the search form in you view:</h2>
<p>I add my little form on the view :</p>
<pre class="brush: c;">

&lt;% using (Html.BeginForm(&quot;List&quot;,&quot;Merge&quot;))
{%&gt;

&lt;label for=&quot;Email&quot;&gt;Email:&lt;/label&gt;
&lt;%=Html.TextBox(&quot;Email&quot;)%&gt;

&lt;label for=&quot;City&quot;&gt;City:&lt;/label&gt;
&lt;%=Html.TextBox(&quot;City&quot;)%&gt;

&lt;input id=&quot;searchform&quot;  type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
&lt;%}%&gt;
</pre>
<p>We add a method for the post :</p>
<pre class="brush: c;">

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult List(FormCollection forms)
{

string Email = Request.Form[&quot;Email&quot;];
string City = Request.Form[&quot;City&quot;];

var res = _dbService.getUserFromDb().AsQueryable();

if (!string.IsNullOrEmpty(Email))
res = res.LikeEmail(Email);

if (!string.IsNullOrEmpty(City))
res = res.WithCity(City);

return View(res);
}
</pre>
<p>Run the application and make a search with  an email and it works !</p>
<h2>Step 8 : Conclusion and improvements :</h2>
<p>Of course, the design of this little application could be discussed but I make a phone book in 10 minutes and I am sure that after one day of refactoring, I could put this application in a production status (Add pagination, add improvemnts for query, some javascript,&#8230;).</p>
<p>So, I am waiting for your feedback&#8230;</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d330').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d330" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;title=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;title=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;title=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;title=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;title=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29+@+http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/&amp;t=ASP.NET+MVC+C%23+Linq+to+Stored+procedure+with+Dynamic+Query+%28a+quick+phone+book%2C+piece+of+Cake+%21%29" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d330').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d330').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/06/12/aspnet-mvc-c-linq-to-stored-procedure-with-dynamic-query-a-quick-phone-book-piece-of-cake/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>C#.NET &#8211; How to extend the .NET Framework easily (extension Methods)</title>
		<link>http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/</link>
		<comments>http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 18:02:50 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=342</guid>
		<description><![CDATA[For example, you want a method who validate if a string is an email or not.
You create a static class, StringExtensions for example, you put it public static and you add a method who take a string and verify if it is a mail or not.
Like this :
&#60;/pre&#62;
public static class StringExtensions
{
public static bool IsNotEmail (this [...]]]></description>
			<content:encoded><![CDATA[<p>For example, you want a method who validate if a string is an email or not.</p>
<p>You create a static class, StringExtensions for example, you put it public static and you add a method who take a string and verify if it is a mail or not.</p>
<p>Like this :</p>
<pre class="brush: c;">&lt;/pre&gt;
public static class StringExtensions
{
public static bool IsNotEmail (this string email)
{
var reg = new Regex(@&quot;^(([^&lt;&gt;()[\]\\.,;:\s@\&quot;&quot;]+&quot;

+ @&quot;(\.[^&lt;&gt;()[\]\\.,;:\s@\&quot;&quot;]+)*)|(\&quot;&quot;.+\&quot;&quot;))@&quot;

+ @&quot;((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&quot;

+ @&quot;\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+&quot;

+ @&quot;[a-zA-Z]{2,}))$&quot;);
if(reg.IsMatch(email))
{
return true;
}

return false;

}

}
&lt;pre&gt;</pre>
<p>Now back to the class where you want to use this extension.</p>
<p>After a dot on a string variable, you will see it in the intellisense:</p>
<p><img class="alignnone size-full wp-image-344" title="intelisense_extension" src="http://blog.dervalp.com/wp-content/uploads/2009/06/intelisense_extension.png" alt="intelisense_extension" width="435" height="182" /></p>
<pre class="brush: c;">

string email = &quot;tralala@something.com&quot;;

if (email.IsEmail())

{
//do something

}
</pre>
<p>That&#8217;s awesome, is that not ?</p>
<p>Indeed, when you put the magic word &#8220;this&#8221; in a static method insided a static class, VS will browse all the methods who take a string object in argument and will add it to intellisense.</p>
<p>How do I use it ?</p>
<p>As soon as I see that I will need a simple method for a particular type very often, I extend this type and add it to a homemade library( which contains all the extension methods I create). Of course put in your library only the standard object of the .NET framework otherwise you will get some compilation errors.</p>
<p>You are now able to use all the power provided by the intellisense.</p>
<p>For example, you have a new developer in your team. He does not need to search in the project where the functions are. He simply put a dot after his variable and he will see what is available. Moreover, if he is new with the .NET Framework, he will believe that it is included by default <img src='http://blog.dervalp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>related link : <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb383977.aspx</a></p>
<p>I expect my introduction to extension methods was clear, if not, do not hesitate to leave a comment&#8230;</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d342').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d342" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;title=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;title=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;title=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;title=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;title=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29+@+http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/&amp;t=C%23.NET+%26%238211%3B+How+to+extend+the+.NET+Framework+easily+%28extension+Methods%29" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d342').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d342').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/06/12/cnet-how-to-extend-the-net-framework-easily-extension-method/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>French blog is comming</title>
		<link>http://blog.dervalp.com/2009/06/04/french-blog-is-comming/</link>
		<comments>http://blog.dervalp.com/2009/06/04/french-blog-is-comming/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 16:27:35 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=322</guid>
		<description><![CDATA[I decide to create a french blog, I notice that they are not a lot of interesting blogs in french which talks about agile, ddd, tdd,&#8230;
So, in place to express my little knowledge in a language who is not mine, I prefer to use my native language and improve the quality of my post.
Anyway, I [...]]]></description>
			<content:encoded><![CDATA[<p>I decide to create a french blog, I notice that they are not a lot of interesting blogs in french which talks about agile, ddd, tdd,&#8230;</p>
<p>So, in place to express my little knowledge in a language who is not mine, I prefer to use my native language and improve the quality of my post.</p>
<p>Anyway, I will keep this blog for the technical parts (C#, ASP.NET,..).</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d322').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d322" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;title=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;title=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;title=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;title=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;title=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+French+blog+is+comming+@+http://blog.dervalp.com/2009/06/04/french-blog-is-comming/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/06/04/french-blog-is-comming/&amp;t=French+blog+is+comming" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d322').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d322').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/06/04/french-blog-is-comming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC : Url Helper Extension CSS, Javascript, Picture</title>
		<link>http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/</link>
		<comments>http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/#comments</comments>
		<pubDate>Fri, 29 May 2009 20:16:56 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Url]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=303</guid>
		<description><![CDATA[Here a url helper, maybe it can interests you :


public static class UrlHelperExtension
{
public static string Image(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&#34;~/Content/Images/{0}&#34;,fileName));
}

public static string Stylesheet(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&#34;~/Content/Css/{0}.css&#34;,fileName));
}

public static string Javascript(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&#34;~/Content/Scripts/{0}.js&#34;, fileName));
}
}

And here is how I use it :
For CSS :


&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;&#60;%= Url.Stylesheet(&#34;reset&#34;) %&#62;&#34; media=&#34;all&#34; /&#62;

For javascript


&#60;script [...]]]></description>
			<content:encoded><![CDATA[<p>Here a url helper, maybe it can interests you :</p>
<pre class="brush: c;">

public static class UrlHelperExtension
{
public static string Image(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&quot;~/Content/Images/{0}&quot;,fileName));
}

public static string Stylesheet(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&quot;~/Content/Css/{0}.css&quot;,fileName));
}

public static string Javascript(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format(&quot;~/Content/Scripts/{0}.js&quot;, fileName));
}
}
</pre>
<p>And here is how I use it :</p>
<p>For CSS :</p>
<pre class="brush: html;">

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;&lt;%= Url.Stylesheet(&quot;reset&quot;) %&gt;&quot; media=&quot;all&quot; /&gt;
</pre>
<p>For javascript</p>
<pre class="brush: html;">

&lt;script src=&quot;&lt;%= Url.Javascript(&quot;jquery-1.3.2.min&quot;) %&gt;&quot; type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;
</pre>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d303').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d303" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;title=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;title=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;title=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;title=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;title=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture+@+http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/&amp;t=ASP.NET+MVC+%3A+Url+Helper+Extension+CSS%2C+Javascript%2C+Picture" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d303').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d303').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/29/aspnet-mvc-url-helper-extension-css-javascript-picture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kiwi MVC.NET : Why this, why that ? I explain my architecture choices Part 5 [source on codeplex]</title>
		<link>http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/</link>
		<comments>http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/#comments</comments>
		<pubDate>Fri, 29 May 2009 18:26:39 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[MVC.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=283</guid>
		<description><![CDATA[So, I work hard these days to  finish my data access. I would like to explain you how I see application&#8217;s design.
As I told you before, I want to separate my application in 3 parts. I know that architecture could be discussed but I would make this point clear, it should be &#8220;re-factored&#8221;. Anyway, for [...]]]></description>
			<content:encoded><![CDATA[<p>So, I work hard these days to  finish my data access. I would like to explain you how I see application&#8217;s design.</p>
<p>As I told you before, I want to separate my application in 3 parts. I know that architecture could be discussed but I would make this point clear, it should be &#8220;re-factored&#8221;. Anyway, for the moment, I think it is enough flexible for what I want to do <span style="text-decoration: underline;">NOW</span>.</p>
<p>Here is a reminder of my layers:</p>
<ul>
<li>The Web application which will be the view of my application.</li>
</ul>
<ul>
<li>The controller with all my business logic embedded in a library Service.</li>
</ul>
<ul>
<li>The model library which will contain my models, my data access (repository) and all my filter static classes.</li>
</ul>
<h2><span id="more-283"></span></h2>
<p>To improve my explanations, I hand draw a little pseudo UML diagram :</p>
<p><img class="alignnone size-full wp-image-287" title="kiwi_mvc_pseudo_uml" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_mvc_pseudo_uml.jpg" alt="kiwi_mvc_pseudo_uml" width="805" height="626" /></p>
<p>What I want it is to keep as much as I can the &#8220;Soc&#8221; (separation of concern). My service should make what a service should do and if I want to change my repository with a Oracle one, I could change it only by modifying the instantiation of my service (with DI for the future). I want to keep that &#8220;philosophy&#8221; all along the development but philosophy is not obligation.</p>
<p>In the same way, you&#8217;ve certainly noticed that I often return an IQueryable for my &#8220;get&#8221; method (see listing 1). I know this should be better to return a List type cause it is a more &#8220;standard&#8221; and you do not have to use the Linq library. Nevertheless I think I will keep it. I do not want to call to often the .IEnumerable function and also it will be easier to use my filter classes.</p>
<p>As the only developer for this application, I assume my choices. <img src='http://blog.dervalp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you have remarks about this, please leave a comment.</p>
<p>Listing 1 : Example of the getPages method who retreive all the page from my db</p>
<pre class="brush: c;">

public IQueryable&lt;Page&gt; getPages()
{

return from p in _db.Posts
where p.Type == &quot;Page&quot;
let lp = getLocalizedPages(p.PostID)
select new Page
{
PageID = p.PostID,
Author = p.Author,
Date = p.Date,
PageLozalized = new LazyList&lt;PageLocalized&gt;(lp),
ModifiedDate = p.ModifiedDate,
Password = p.Password ?? string.Empty,
Permalink = p.Permalink,
Status = p.PostStatusID,
Version = p.RevisionOf

};
}

private IQueryable&lt;PageLocalized&gt; getLocalizedPages(int postID)
{
return from lp in _db.PostCultureDetails
where lp.PostID == postID
select new PageLocalized()
{
Description = lp.Excerpt,
Text = lp.Text,
Title = lp.Title,
LanguageCode = (from culture in _db.Cultures
where culture.CultureID == lp.CultureID
select culture.LanguageCode).SingleOrDefault()

};

}
</pre>
<p><strong>Why I did not use Entity framework ?</strong> I hate when the framework decide for me which object I should use. Also, the time I would spend to make it work as I want is doubtless longer than the time I wrote my custom Linq to Sql Class. Entity framework could be great for simple application but for an application who will grow in the future (as I expect Kiwi will do) I do not think it&#8217;s a good choice.</p>
<p><strong>Why I did not use NHibernate ? </strong>I could have chosen NHibernate, but I absolutely wanted to play with Linq. Also, maybe in the future I could make the data access with it and compare what&#8217;s better for my application. Anyway, this is not the time to do this.</p>
<p>If you have other questions like this, please, do not hesitate.</p>
<p><strong>And now the service :<br />
</strong></p>
<p>As I mentioned, my data access is almost finished (for the moment). I am going to create the services I need for my application. Evidently, always in a TDD approach.</p>
<p><strong>Kiwi Part 4 was bullshit :</strong></p>
<p>Maybe it was but the aim of that post was to show you how to start with TDD. And I know that I was going in front of a wall. Indeed, I had an empty db and the post object was the most connected object. As you know in TDD, you write a test, you write <span style="text-decoration: underline;">some code</span>. I realized that I should have written a lot (before creating the &#8220;SaveFunction&#8221; for it). I needed the category object, the comment object,&#8230; Thus, I begin to create a save function for the category object (alway with a tdd style).</p>
<p>Create the test :</p>
<pre class="brush: text;">
//Spike Test !!!
[TestMethod]
public void SqlPostRepositoryTest_can_add_category()
{

Category category = new Category();
category.CreatedDate = DateTime.Now;
category.CategoryParentID = 0;
var categoryEn = new CategoryLocalized() {Description = &quot;This is a test&quot;, Value = &quot;Software Development&quot;, LangageCode = &quot;EN&quot;};
var categoryFR = new CategoryLocalized() { Description = &quot;Ceci est un test&quot;, Value = &quot;Développement Logiciel&quot;, LangageCode = &quot;FR&quot; };

var list = new LazyList&lt;CategoryLocalized&gt;();
list.Add(categoryEn);
list.Add(categoryFR);

category.LocalizedCategory = list;

_repository.Save(category);

Assert.IsNotNull(category);

}
</pre>
<p>And after the function I need :</p>
<pre class="brush: c;">

//save or add a category

public void Save (Category category)
{
var dbCategory = (from c in _db.Categories
where c.CategoryID == category.CategoryID
select c).SingleOrDefault();
if(dbCategory == null)
{
dbCategory = new SqlRepository.Category();
dbCategory.CreatedDate = DateTime.Now;
dbCategory.ParentID = category.CategoryParentID;
//commit the change to have the id and insert the culture
_db.Categories.InsertOnSubmit(dbCategory);
_db.SubmitChanges();

//foreach culture we have in the objec we add it in the table CategoryCultureDetail
foreach (CategoryLocalized item in category.LocalizedCategory)
{
var dbitem = new CategoryCultureDetail();
//some Object to DB
dbitem.CategoryID = dbCategory.CategoryID;
dbitem.Description = item.Description;
dbitem.Value = item.Value;
dbitem.CultureID =
(from culture in _db.Cultures
where culture.LanguageCode == item.LangageCode
select culture.CultureID).SingleOrDefault();
dbCategory.CategoryCultureDetails.Add(dbitem);
_db.SubmitChanges();
}

}
else
{

foreach (CategoryLocalized item in category.LocalizedCategory)
{
var thisCategoryLocalized = (from cn in _db.CategoryCultureDetails
where cn.CategoryID == category.CategoryID
where cn.CultureID ==   (from culture in _db.Cultures
where culture.LanguageCode == item.LangageCode
select culture.CultureID).SingleOrDefault()
select cn).SingleOrDefault();
thisCategoryLocalized.Description = item.Description;
thisCategoryLocalized.Value = item.Value;
_db.CategoryCultureDetails.InsertOnSubmit(thisCategoryLocalized);
_db.SubmitChanges();

}
}
}
</pre>
<p>Of course, you see the &#8220;final&#8221; result. To have that, I went by little piece of code. Test, write, build, test, write, build, test &#8230;</p>
<p>I also know the test you see above is not a unit test, it is more an integration test or a spike test and it will be deleted or commented in the future.</p>
<p>But the name is <span style="text-decoration: underline;">test driven </span>design and not &#8220;make pure unit test&#8221; design.</p>
<p>NOTE : I know I am saying that each time I post but I will try to add the source code in my codeplex project this afternoon.</p>
<p>UPDATE  : I put the source on code plex, if you would like to see it : http://dervalp.codeplex.com/</p>
<p>I have some troubles with codeplex, I will check this out tomorrow cause I am a bit tired today.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d283').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d283" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;title=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;title=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;title=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;title=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;title=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D+@+http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/&amp;t=Kiwi+MVC.NET+%3A+Why+this%2C+why+that+%3F+I+explain+my+architecture+choices+Part+5+%5Bsource+on+codeplex%5D" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d283').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d283').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/29/kiwi-mvcnet-why-this-why-that-i-explain-my-architecture-choices-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#.NET Linq to Sql : System.Data.Linq.ChangeConflictException: Row not found or changed..</title>
		<link>http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/</link>
		<comments>http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/#comments</comments>
		<pubDate>Fri, 29 May 2009 16:18:53 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=278</guid>
		<description><![CDATA[I received this error during a get method (retreive the posts in my Kiwi Application).
I strangled with this during an hour and finally, I remembered that I had changed a NOT NULL field in my db to a allow null number.
So, when you do that, you simply have to update your Linq to Sql (dbml). [...]]]></description>
			<content:encoded><![CDATA[<p>I received this error during a get method (retreive the posts in my Kiwi Application).</p>
<p>I strangled with this during an hour and finally, I remembered that I had changed a NOT NULL field in my db to a allow null number.</p>
<p>So, when you do that, you simply have to update your Linq to Sql (dbml). Hope it helps.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d278').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d278" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;title=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;title=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;title=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;title=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;title=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed..+@+http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/&amp;t=C%23.NET+Linq+to+Sql+%3A+System.Data.Linq.ChangeConflictException%3A+Row+not+found+or+changed.." rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d278').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d278').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/29/cnet-linq-to-sql-systemdatalinqchangeconflictexception-row-not-found-or-changed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Kiwi MVC.NET : Let&#8217;s go to TDD ! Part 4</title>
		<link>http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/</link>
		<comments>http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/#comments</comments>
		<pubDate>Wed, 27 May 2009 20:24:28 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[MVC.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=233</guid>
		<description><![CDATA[So, now that I have introduced TDD in my Agile Page. I will try to use it along all the development of Kiwi.

First, I add to my Test project, 3 folders.

ControllerTest : where I will put all my tests related with a controller.


TestRepositories : there I will create fake repositories, to know if my service [...]]]></description>
			<content:encoded><![CDATA[<p>So, now that I have introduced TDD in my Agile Page. I will try to use it along all the development of Kiwi.</p>
<h3><span id="more-233"></span></h3>
<p>First, I add to my Test project, 3 folders.</p>
<ul>
<li>ControllerTest : where I will put all my tests related with a controller.</li>
</ul>
<ul>
<li>TestRepositories : there I will create fake repositories, to know if my service will work with other repositories.</li>
</ul>
<ul>
<li>IntegrationTest : there I will put all my tests related with the repositories. It will contain some “Spike Test”.</li>
</ul>
<p><img class="alignnone size-full wp-image-258" title="tdd_projects" src="http://blog.dervalp.com/wp-content/uploads/2009/05/tdd_projects.jpg" alt="tdd_projects" width="347" height="269" /></p>
<p>Maybe, I will change this structure in the future.</p>
<p>For this example, you need to have the model Post. This model have some properties and one lazylist of PostLocalized.</p>
<pre class="brush: c;">

public class Post
{
public int PostID { get; set; }
public string Author { get; set; }
public string Status { get; set; }
public DateTime Date { get; set; }
public DateTime ModifiedDate { get; set; }
public string Version { get; set; }
public string Permalink { get; set; }
public string Password { get; set; }
public LazyList&lt;PostLocalized&gt; LocalizedPost { get; set; }
}
public class PostLocalized
{
public string Title { get; set; }
public string Text { get; set; }
public string Excerpt { get; set; }
public string LanguageCode { get; set; }
}
</pre>
<p>Back to the code, I want to create a test which return a list of post form the DB. I created a class SqlCMSRepositoryTest in my IntegrationTest folder.If I write the code in VS (like you can see in the picture here under) VS says me that the function GetAll() does not exsit. Without executing the test, I know that we have to create this function. Normally in a pure TDD way, you should try to rebuild and see if it succeed.  Of course, you will get an error. So, let&#8217;s correct it.</p>
<p><img class="alignnone size-full wp-image-261" title="kiwi_part4_0" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part4_0.jpg" alt="kiwi_part4_0" width="667" height="358" /></p>
<p>To correct it, I create a function GetPosts in the SqlCMSRepositories. Here is the code :</p>
<pre class="brush: c;">
using System.Collections.Generic;
using System.Linq;
using CMS.MVC.Data.SqlRepository;

namespace CMS.MVC.Data
{
public class SqlCMSRespository
{
//the name we changed in the properties of our Linq to Sql class
private DB _db;

//constructor
#region .ctor

//we instanciate the db when we instantciate the SqlCMSRespository
//default constructor
public SqlCMSRespository()
{
_db = new DB();
}

public SqlCMSRespository(DB dataContext)
{
//override the current context with the on passed in
//for TDD
_db = dataContext;
}

#endregion

#region Post

public IQueryable&lt;Post&gt; getPosts()
{
var res = new List&lt;Post&gt;();
return res.AsQueryable();
}

#endregion
}
}
</pre>
<p>When I try to build I receive error, indeed, I instantiated the SqlCMSRepositoryTest in place of the SqlCMSRepository. Also, I should add a reference to the data library and decorate the class with the attribute [TestClass]. Oh it is  a lot of mistakes, isn&#8217;t it ?</p>
<p>After correcting the code, I build the solution and I execute the test with this code :</p>
<pre class="brush: c;">

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CMS.MVC.Data;

namespace CMS.MVC.Web.Tests
{
[TestClass]
public class SqlCMSRepositoryTest
{
private SqlCMSRespository _repository;

/// &lt;summary&gt;
/// Loading the SqlCMSRepository each time we use the SqlCMSRespositoryTest
/// &lt;/summary&gt;
[TestInitialize]
public void Setup()
{
_repository = new SqlCMSRespository();
}

[TestMethod]
public void can_get_all_post()
{
List&lt;Post&gt; PostList = _repository.getPosts().ToList();
Assert.IsNotNull(PostList);
}

}
}
</pre>
<p>The test passes.</p>
<p><img class="alignnone size-full wp-image-262" title="kiwi_part4_2" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part4_2.jpg" alt="kiwi_part4_2" width="951" height="190" /></p>
<p>So, now I go beyond, I will create another test method. I would like to do the same test but count if there is 2 posts in the db post.</p>
<p>But my db is empty, so before, I write a test &#8220;can_create_post&#8221;.</p>
<pre class="brush: c;">
[TestMethod]
public void can_create_post()
{
Post thisPost = new Post();
thisPost.Author = &quot;dervalp&quot;;
thisPost.Date = DateTime.Now;
thisPost.ModifiedDate = DateTime.Now;
thisPost.Password = string.Empty;
thisPost.Permalink = string.Empty;
thisPost.Version = string.Empty;
thisPost.Status = &quot;Post&quot;;

PostLocalized PostContentEN = new PostLocalized();
PostContentEN.Excerpt = &quot;This is a resum&quot;;
PostContentEN.LanguageCode = &quot;EN&quot;;
PostContentEN.Title = &quot;Titre du post&quot;;
PostContentEN.Text = &quot;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&quot;;
var ListLocalizedPost = new LazyList&lt;PostLocalized&gt;();
ListLocalizedPost.Add(PostContentEN);
thisPost.LocalizedPost = ListLocalizedPost;

//create the post in the db
_repository.Add(thisPost);

//It the application throw an exception the test will fail
Assert.IsNotNull(thisPost);

}
</pre>
<p>&#8220;thisPost&#8221; is never null but if it will throw you an exception if your test fails. So, I rebuild and execute the test. It fails.</p>
<p>To succeed the test, I add the function, Add() in my SqlCMSRespository :</p>
<pre class="brush: c;">
public void Add(Post post)
{

}
</pre>
<p>So now, I execute the test and It succeeds. As I am stupid, I will create another test. I will make the have_post_one_item_in_db.</p>
<pre class="brush: c;">

[TestMethod]
public void have_post_one_item_in_db()
{
var res = _repository.getPosts();

Assert.AreEqual(1, res.Count());
}
</pre>
<p>Of course, it fails. So to make this test passes, I have to adapt my function add.</p>
<p>I think, you understand the idea now. I will update this post with a more complete SqlCMSRespository class.</p>
<p>Feedback is welcome.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d233').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d233" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;title=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;title=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;title=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;title=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;title=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4+@+http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/&amp;t=Kiwi+MVC.NET+%3A+Let%26%238217%3Bs+go+to+TDD+%21+Part+4" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d233').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d233').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/27/kiwi-mvc-lets-go-to-tdd-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agile &#8211; Test Driven Design &#8220;Need it or not Need it&#8221;</title>
		<link>http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/</link>
		<comments>http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/#comments</comments>
		<pubDate>Wed, 27 May 2009 09:43:34 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=237</guid>
		<description><![CDATA[What my colleagues often say when they hear TDD is :  &#8220;It makes no sense&#8221;, &#8220;We do not need that&#8221;, &#8220;I am doing without TDD since ten years&#8221;.
Indeed, maybe, you do not need it. Indeed, you were doing without it but if you are a developer, you should be open to new technologies, curious and [...]]]></description>
			<content:encoded><![CDATA[<p>What my colleagues often say when they hear TDD is :  &#8220;It makes no sense&#8221;, &#8220;We do not need that&#8221;, &#8220;I am doing without TDD since ten years&#8221;.</p>
<p>Indeed, maybe, you do not need it. Indeed, you were doing without it but if you are a developer, you should be open to new technologies, curious and maybe you should test it before saying that you do not need it.</p>
<p>Main bugs come from stupid errors. If you use TDD, a lot of this (syntax, typo, omission) error will emerge quickly.</p>
<h2><span id="more-237"></span></h2>
<p>To make your code testable you have to understand all the methods and objects you use. I think it is the main reason why some developers fear about TDD cause if you want to simulate your httpcontext for example, you have to understand how a httpcontext works.  Also, to do that, you have to &#8220;mock&#8221;, good tools exist to help developers to setup fake context but It cost you time.</p>
<p>Is it worth? I would say yes. In the end of the process,  you can be self-confident with your code and you can explain to everyone what you are doing without gray area. Moreover, if you change something in your code, you should be able to know if there are side effects or not. You will execute all your tests and if all your tests pass, you are safe. If not, you can immediately  know where you have to change.</p>
<p>The other great thing with TDD is the iterative way. You create a test, it fails, you write some code, you execute the test, if it is ok, you write a new test,&#8230; Like this you feel less overwhelmed by your project.</p>
<p><img class="alignnone size-full wp-image-244" title="tdd_test" src="http://blog.dervalp.com/wp-content/uploads/2009/05/tdd_test.jpg" alt="tdd_test" width="380" height="732" /></p>
<p>The definition from Wikipedia :</p>
<p><em>Test-driven development (TDD) is a software development technique that uses short development iterations based on pre-written test cases that define desired improvements or new functions. Each iteration produces code necessary to pass that iteration&#8217;s tests. Finally, the programmer or team refactors the code to accommodate changes. A key TDD concept is that preparing tests before coding facilitates rapid feedback changes. Note that test-driven development is a software design method, not merely a method of testing.</em></p>
<p>“The act of writing a unit test is more an act of design than of verification.<span> </span>It is also more an act of documentation than of verification.<span> </span>The act of writing a unit test closes a remarkable number of feedback  loops, the least of which is the one pertaining to verification of function”.<a href="http://www.amazon.com/exec/obidos/ASIN/0135974445/ambysoftinc"> Bob Martin</a></p>
<p>I guess it is what a developer should understand. Writing a test is not only test but it a act of design.</p>
<p>For example, we have an application who manage flights in the Airport X. And the client want to see all the flight details who land between 3 PM and 4 PM in that Airport. The questions are : What do you need ? Where do I have to query the data ? Also, maybe you have to deal with 5 or 6 web services.  How are you going to test this function without unit tests ?  Are you going to create a gridview to see the results and go in debug mode ? It is going to be a nightmare. But if you go step by step by using TDD, I am sure it will be easier cause when you will write your tests, you will ask the right questions and you will better understand the domain you are dealing with. It is, &#8220;Think before programming&#8221;.</p>
<p>In conclusion, I am not going to explain how TDD is working. I know some websites explain that better than me. I will give you some links that I&#8217;ve found usefull during my learning process.  Also, maybe my opinion on TDD will change, in that case, I will update this post. As usual, feeback is welcome.</p>
<p>Related Links :</p>
<p><a href="http://www.agiledata.org/essays/tdd.html">Wikipedia</a></p>
<p><a href="http://www.agiledata.org/essays/tdd.html">AgileData</a></p>
<p><a href="http://blog.wekeroad.com/tag/tdd/">Rob Connery</a></p>
<p><a href="http://haacked.com/Tags/TDD/default.aspx">Phil Haack</a></p>
<p>NOTE : For my unit tests, I am using Visual Studio 2008 SP1. I used <a href="http://www.nunit.org/index.php">Nunit</a> in the past but, for me, VS makes a good job with unit test so I&#8217;ve switched. If you have feedback in that topic, you&#8217;re welcome.</p>
<p>NOTE2 : TDD without Mocking is not TDD, I will write a post about that in the future.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d237').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d237" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;title=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;title=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;title=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;title=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;title=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B+@+http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/&amp;t=Agile+%26%238211%3B+Test+Driven+Design+%26%238220%3BNeed+it+or+not+Need+it%26%238221%3B" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d237').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d237').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/27/agile-test-driven-design-i-do-need-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kiwi MVC.NET : Prepare your data access Part3</title>
		<link>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/</link>
		<comments>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/#comments</comments>
		<pubDate>Tue, 26 May 2009 20:03:45 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[Localized]]></category>
		<category><![CDATA[MVC.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=196</guid>
		<description><![CDATA[So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous [...]]]></description>
			<content:encoded><![CDATA[<p>So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous post, a security layer is a kind of plugin. Therefore, we could add it later.</p>
<p>Today, I will show you how I am going to create the models and prepare my data access with the help of LinqToSql class.</p>
<p>I choose to make Kiwi multilingual.</p>
<h2><span id="more-196"></span></h2>
<h2>1) The DB</h2>
<p>I am not a dba, you are welcome with your feedback.</p>
<p>Here is the design I choose :</p>
<p><img class="alignnone size-full wp-image-206" title="kiwi_db" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_db.jpg" alt="kiwi_db" width="833" height="780" /></p>
<h2>2) The models</h2>
<p>I decided to create five objects to begin the project. An object Post, Page, Comment, Tag and Category.</p>
<ul>
<li>The object Post : It is a content of a news (for the moment). A post must be in a category. There are status for this type. A post cannot have subposts. This object is localized</li>
</ul>
<ul>
<li>The object Page : It cannot be a part of a category, the page can have subpages. This object is localized and have the same status (puslihed, offline,&#8230;) than a post object.</li>
</ul>
<ul>
<li>The object Comment : A classic comment object, with the author name, the ip address,&#8230; A comment can have child (qutoes). This object is not localized (for the moment, we could think of an automatic translation but KISS).</li>
</ul>
<ul>
<li>The object Category :  This object contains the post. It is localized by the name.</li>
</ul>
<p>Example for Page:</p>
<p>I use the LazyList pattern (<a href="http://blog.wekeroad.com/blog/lazy-loading-with-the-lazylist/">more info here</a>). I will put the project on codeplex, like this, you will able to browse and download the code.</p>
<pre class="brush: c;">

namespace KIWI.MVC.Data
{
class Page
{
public int PageID { get; set; }
public string Author { get; set; }
public string Status { get; set; }
public DateTime Date { get; set; }
public DateTime ModifiedDate { get; set; }
public string Version { get; set; }
public string Permalink { get; set; }
public string Password { get; set; }
public LazyList&lt;Page&gt; PageChild{ get;set;}
public LazyList&lt;Page&gt; PageLozalized { get; set; }
}
public class PageLocalized
{
public string Title { get; set; }
public string Text { get; set; }
public string Excerpt { get; set; }
public string LanguageCode { get; set; }
}
}
</pre>
<h2>3) The SqlCMSRepository</h2>
<p>This repository will be the link between my object and my db. It will contain all the main method I need. I will always return an IQueryable type.  It will allow you to use the <a href="http://en.wikipedia.org/wiki/Pipes_and_filters">pipeline pattern</a> to create some filter functions.</p>
<ul>
<li>Create a LinqToSql class.</li>
</ul>
<p><img class="alignnone size-full wp-image-212" title="kiwi_linq_to_sql" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_linq_to_sql.jpg" alt="kiwi_linq_to_sql" width="683" height="414" /></p>
<p>After creating the linq to sql class, drop the table you need from the server explorer of visual studio to the dml file.</p>
<p><img class="alignnone size-full wp-image-215" title="kiwi_class_cms" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_cms.jpg" alt="kiwi_class_cms" width="253" height="323" /></p>
<p>You will have the representation of you db (like the first page of this post). After, change some properties of you LinqCMSRespository class. Double clik on the LinqCMDRespository.dbml and right click on the screen where your tables appear. Here change the Name to &#8220;DB&#8221;. It is only to use the same name for you future dbml and improve the visibilty of your code.</p>
<p><img class="alignnone size-full wp-image-216" title="kiwi_class_linq_properties" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_linq_properties.jpg" alt="kiwi_class_linq_properties" width="311" height="253" /></p>
<p>Build you solution to see if everything goes well.</p>
<p>If you have built successfully, then create you SqlCMSRespository class.</p>
<p>Here is the code :</p>
<pre class="brush: c;">
using CMS.MVC.Data.SqlRepository;

namespace CMS.MVC.Data
{
class SqlCMSRespository
{
//the name we changed in the properties of our Linq to Sql class
private DB _db;

//constructor
#region .ctor

//we instanciate the db when we instantciate the SqlCMSRespository
//default constructor
public SqlCMSRespository()
{
_db = new DB();
}

public SqlCMSRespository(DB dataContext)
{
//override the current context with the on passed in
//for TDD
_db = dataContext;
}

#endregion

#region Post
//there we will put our main functions like GetPost(),...
//But before, let's go to TDD !!!!
//TEST DRIVEN DESIGN
#endregion
}
}
</pre>
<p>Now we are able to begin all our data access method but before writing some code in your repository, we&#8217;ll go with the TDD approach.<br />
And by creating our tests, we will see what we need in our application.</p>
<p>So this is the end for today, as usual, feedback and comments are very appreciated.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d196" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3+@+http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;t=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
