By default, the entity framework works on a lazy load mode. this means that, if you want to load a reference, you must do it explicitly.
Imagine the scenario:

Linq example
Normally, when we make a linq query to get all the Person we would do:
Entities entities = new Entities(); var persons = from Person p in entities.Person select p;
but in this scenario, if we wanted the books, we have to explicitly load then:
foreach(Person p in persons){
p.Book.Load();
//Handle the books
}
This would do a query for each person just to retrieve the books.
But you can explicitly load the books right in the query:
Entities entities = new Entities();
var persons = from Person p in entities.Person.Include("Book")
select p;
this would allow you to load all the books from all the persons. This is called eager loading.
If you want to retrive all the persons and all the books and all the pages of those books, the query would be:
Entities entities = new Entities();
var persons = from Person p in entities.Person.Include("Book.Page")
select p;
Here an interesting site comparing the speed of 5 of the most known JS frameworks on the market:
http://mootools.net/slickspeed/
My results in several Browsers:
XP/Firefox:
Mootools: 157 ms
JQuery: 147 ms
Prototype: 215 ms
YUI: 342 ms
Dojo: 101 ms
XP/IE7:
Mootools: 416 ms
JQuery: 302 ms
Prototype: 1598 ms
YUI: 999 ms
Dojo: 503 ms
XP/Opera:
Mootools: 68 ms
JQuery: 64 ms
Prototype: 80 ms
YUI: 250 ms
Dojo: 28 ms
XP/Chrome:
Mootools: 68 ms
JQuery: 49 ms
Prototype: 291 ms
YUI: 215 ms
Dojo: 61 ms
The winner is: Dojo!!!
Is really fast in the major browsers (IE doesn’t count.. every javascript is slow on IE.. :\).
Many times i’m programming and i want to iterate a collection and modify it. Thsi usually happens when i want to remove a certain number of objects of a collection:
foreach( Element e in elements){
if( ConditionIsSatisfied(e) ) {
elements.Remove(e);
}
}
The above method will give a collection modified exception because i’m modifying a collection while iterating it.
To resolve this problem without long lines of code, there is a simple thing i can do:
List<Element> temporayElements = new List<Element>(elements);
foreach( Element e in temporayElements){
if( ConditionIsSatisfied(e) ) {
elements.Remove(e);
}
}
This way, i can iterate and check the conditions in one container and manipulate the original one without the possibility of throwing a “Collection was modified” exception.
It is known that Microsoft has adopted JQuery has it’s “official” javascript Framework.
Now it is possible to have, in Visual Studio 2008, intellisense using this javascript framework.
In this post made by Scott Guthrie he shows how to install this support in javascript.
Although i don’t use JQuery (by some reason i prefer Mootools) it is a very good feature to add to visual studio. I know what it costs me to program using Mootools docs page has a support. Having intellisense would become things so much easy!
Double click is a feature that can useful when you build a Site. Almost every element can have a double click event. It’s usage is very simple:
<div ondblclick=’alert(”Hello”)’>Hello</div>
Elements like
<select id='listItem' multiple="true"> <option value="hello">Hello</option> <option value="hello2">Hello2</option> </select>
Javascript Code using Mootools
$("listItem").addEvent('dblclick',function(evt){
var v = this.selectedIndex;
alert(v.value);
});
To do this i use mootools, a very fast and handy JavaScript framework.
Imagine that you got an element as following:
<img id="image" src="..." aaa="true" />
To get the value attribute “aaa” using mootools you only need to do the following:
$("image").getAttribute("aaa");
This solution will work in all browsers.
A simple ajax request using Mootools:
new Ajax('Ajax.aspx', {
method: 'get',
update: $('updateElement')
}).request();
All worked fine in Firefox and Opera. But in IE didn’t. The request simply wasn’t being made. Why?
Well, it seems that IE makes cache of the request. To avoid this feature, you only need to change the code above into the following:
var ajax = new Ajax('Ajax.aspx', {
method: 'get',
update: $('updateElement')
});
if (window.ie) {
ajax.setHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
}
ajax.request();
“The If-Modified-Since request-header field is used with the GET method to make it conditional: if the requested resource has not been modified since the time specified in this field, a copy of the resource will not be returned from the server; instead, a 304 (not modified) response will be returned without any Entity-Body.”
source: http://www.freesoft.org/CIE/RFC/1945/58.htm
Because the content has been modified since the date passed, the request will be made to the server in order to get a fresh copy of the page.
Other solution could be adding a time stamp to the request, example:add a query string attribute with the current date.

Yeah, it’s true. The creators of “Tower of Goo” created more than 50 games in one semester. An there were only 3 rules:
This is what I call Extreme Game Design (and programming)!
Here is the article that explains this experiment: www.gamasutra.com
You can also see the website of this experiment at www.experimentalgameplay.com

In this second part, i will show how to make an ASP.NET Validation control that uses the reCaptcha framework.
I named this control ReCaptchaValidator. This validator extends the abstract class BaseValidator. And so soon we arrived to the first point.
ReCaptchaValidator could implement the interface IValidator, but he would lose a functionality that is very useful. the property ValidationGroup. This property allows you to tell the validator that he will only make the validation when an input with the same validation group makes a post back.
Example
<asp:Button ValidationGroup="test" runat="server"/>
When the above control makes a post back to the server, only the controls in the validation group named “test” will be called.
So, the ReCaptchaValidater extends BaseValidator. Starting explanation, all the action will occur in the EvaluateIsValid, a method inherited from BaseValidator:
protected override bool EvaluateIsValid() {
string parameters = ReCaptchaParameters();
string result = ValidateCaptcha(parameters);
bool isValid = result.Equals("true\nsuccess");
if( !isValid ) {
ErrorMessage = "Your are not a human!";
Controls.Add( new LiteralControl(ErrorMessage));
}
return isValid;
}
This method will call the private method ReCaptchaParameters that will return all the parameters needed to make the Web Request to the reCaptcha url. This Web Request will be made by the method ValidateCaptcha to which the parameters are passed. (ReCaptchaParameters and ValidateCaptcha are defined below)
Then the result of the Web Request is validated. If the result is different from the string “true\nsuccess”, then the user didn’t inserted the captcha correctly (or a BOT is trying to register in your site).
/// <summary>
/// Gathers the parameters for reCaptchaValidator
/// </summary>
/// <returns></returns>
private static string ReCaptchaParameters() {
string response = GetFormValue("recaptcha_response_field");
string challenge = GetFormValue("recaptcha_challenge_field");
string IP = HttpContext.Current.Request.UserHostName;
StringBuilder builder = new StringBuilder();
builder.AppendFormat( "privatekey={0}&", PrivateKey );
builder.AppendFormat( "remoteip={0}&", IP );
builder.AppendFormat( "challenge={0}&", challenge );
builder.AppendFormat( "response={0}", response );
return builder.ToString();
}
/// <summary>
/// Validates the capcha inserted by the user
/// </summary>
/// <param name="parameters">parameters to verify</param>
/// <returns>response of the capcth</returns>
private static string ValidateCaptcha( string parameters ) {
try {
WebRequest request =
WebRequest.Create( "http://api-verify.recaptcha.net/verify" );
request.ContentType = "application/x-www-form-urlenpred";
request.Method = "POST";
StreamWriter writer =
new StreamWriter( request.GetRequestStream() );
writer.Write( parameters );
writer.Close();
//Response
HttpWebResponse webResponse =
(HttpWebResponse)request.GetResponse();
StreamReader myReader =
new StreamReader( webResponse.GetResponseStream() );
string response = myReader.ReadToEnd();
myReader.Close();
webResponse.Close();
return response;
}catch( WebException ) {
//Do Some Exception threatment
return string.Empty;
}
}
In the Render method we will render all the code necessary to show the reCaptcha validator:
/// <summary>
/// Writes the javascript to show the validation Captcha
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer) {
writer.Write(
@"
<script>
var RecaptchaOptions = {{theme : 'blackglass', tabindex : 2}};
</script>
<script type='text/javascript'
src='http://api.recaptcha.net/challenge?k={0}'&
gt;</script>
<noscript>
<iframe src='http://api.recaptcha.net/noscript?k={0}'
height='300' width='500'
frameborder='0'></iframe><br/>
<textarea name='recaptcha_challenge_field' rows='3'
cols='40'></textarea>
<input type='hidden' name='recaptcha_response_field'
value='manual_challenge'>
</noscript>", PublicKey );
dummy.Visible = false;
base.Render(writer);
}
Noticed the dummy.Visible = false in the render? This is the second point i wanted to talk about. The validators that inherit from BaseValidator were made to validate other controls. In this case, we don’t want to validate any asp.net control. The control we want to validate is provided by a third party code (all the javascript in the render method).
Because of this fact, the validator has an hack. A TextBox with the name “dummy” is created and it’s ID is passed to the property of BaseValidator, ControlToValidate. This way we can surpass the limitation of BaseValidator. Notice that, if this validator didn’t extend BaseValidator, but implemented IValidator, this hack would not be needed.
I made this hack on the event OnInit:
protected override void OnInit(EventArgs e) {
dummy.ID = "aaa";
Controls.Add(dummy);
ControlToValidate = "aaa";
base.OnInit(e);
}
An that’s it. A free captcha control that you can use in all yout web applications.
For your commodity, the ReCaptchaValidator code is available here (in C#) and here (in VB) (Note: the VB code was created using a converter so it might not be exactly like the C# original file).

reCaptcha is a Captcha program that can tell the difference between a human and a machine. And Plus, it helps to digitalize books. And how does it do it?
Recapcha uses a 2 word challenge. A first word, that is an already known word, and a second word that comes from a digitalized book. If the user inserts the known word correctly, then the second word is assumed as correct and you helped to translate a digitalize one word.
A more complete explanation can be found here, at reCaptcha official page.
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=your_public_key"> </script> <noscript> <iframe src="http://api.recaptcha.net/noscript?k=your_public_key" height="300" width="500" frameborder="0"></iframe><br> <textarea name="recaptcha_challenge_field" rows="3" cols="40"> </textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"> </noscript>
And a box, similar to the one below, will appear.

Then, for this process to work, a request must be made to http://api-verify.recaptcha.net/verify with the right parameters in order to validate the captcha.
The steps to do this are:
The Web request you make to the above url will retrieve a response separated by a \n. In the first part of the response, the possible values are true or false. If the first part has the value false, then the second part is the error code. You can find the list of error codes here in the section “Error Code Reference”. This page also has all the information you need make your implementation.
In Part 2 of this article i will show how to implement an ASP.NET Validator control that uses this API.