Posted by: advapi | July 19, 2008

Anonymous type in C# 3.0

While working on my project and I was doing a Select from DB using LINQ, here’s my query

var sql = from o1 in dataContext.AdsForDomains
where o1.IDDomain.Equals(IDDomain)
select new {o1.IDAdsDomain, o1.IDAds, o1.Container, o1.AD.Description, o1.AD.AdsSize, o1.AD.Merchant.Name};

I bounded then this to a GridView and started to working with the gridview behaviour… everything was fine since I needed to read the loaded value from the e.Row.DataItem…. my problem was… how do I read anonymous type value? If I binded a whole row of a table, I would have got the strongly typed object but in this case not…. googling around and doing some test I discovered that in c# 3.0 there’re some limitations about anonymous type (refer to this for better explanation).

He’re what I did, I used the “Cast” method to cast the object inside the e.Row.DataItem to the strongly type I passed to.

protected void gvwAdsForDomains_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItem != null)
{
DropDownList ddl = e.Row.FindControl(”ddlContainer”) as DropDownList;
if (ddl != null)
{
var mytype = Cast(e.Row.DataItem,
new
{
IDAdsDomain = 0,
IDAds = 0,
Container = string.Empty,
Description = string.Empty,
AdsSize = new AdsSize(),
Name = string.Empty
});

ddl.SelectedValue = mytype.Container;
}
}
}

private T Cast<T>(object o, T type)
{
return (T)o;
}

In that way I was able to read the content of fields that where stored inside the anonymous type. I also tryied (with no luck) to get the fields by reflection. I’ll investigate more as soon as I’ll have time.

Hope it helps,

Bests

Posted by: advapi | July 18, 2008

Mario’s corner

A man was in a bad accident and was injured. But the only permanent damage he suffered was the loss of both ears, which made him very self-conscious. However, he received a large sum of money from his insurance company.
It was always his dream to own his own business, so he went out and purchased a small, but expanding computer firm. But he realized that he had no business knowledge at all, so he decided that he would have to hire someone to run the business. He picked out three top candidates, and interviewed each of them. The last question of the interview was always the same.

“Do you notice anything unusual about me?” he asked the first candidate.

“Yes. You have no ears.”

He quickly eliminated the first candidate.

“Do you notice anything unusual about me?” he asked the second candidate.

“Yes. You have no ears.”

He quickly eliminated the second candidate.

“Do you notice anything unusual about me?” he asked the third candidate.

“Yes. You’re wearing contacts.”

Thinking he had found the man for the job he said, “That’s correct. How did you know?”

“You can’t wear glasses if you don’t have any freakin’ ears.”

Posted by: advapi | July 16, 2008

Spazio belle donne

Here we go…..

Posted by: advapi | July 14, 2008

Mario’s corner

He mailed me this twice….. it’s a sign that he wanted it to be published :

A blonde is on a four-engine plane crossing the Atlantic. All of a sudden there’s a loud bang. The pilot announces over the intercom “I’m sorry, one of our engines has just shut off. We’ll be delayed 45 minutes.”
Suddenly there’s another bang. Once again, the intercom clicks on and the pilot expresses his regret that they”ll be delayed two hours.

Shortly thereafter, there is another bang and the pilot announces that they’ll be delayed 3 hours.

The blonde turns to the guy sitting beside her and says, “Man, if the fourth engine shuts off we”ll be up here all day

Posted by: advapi | July 13, 2008

Mario’s corner today teach how to use wii

Thanks Mario:

Posted by: advapi | July 11, 2008

Il successo durante la vita!

A 3 anni il successo è: non pisciarsi addosso.
A 12 anni il successo è: avere tanti amici.
A 18 anni il successo è: avere la patente.
A 20 anni il successo è: avere rapporti sessuali.
A 35 anni il successo è: avere moltissimi soldi.
A 50 anni il successo è: avere moltissimi soldi.
A 60 anni il successo è: avere rapporti sessuali..
A 70 anni il successo è: avere la patente.
A 75 anni il successo è: avere tanti amici.
A 80 anni il successo è: non pisciarsi addosso!

Posted by: advapi | July 11, 2008

Speeding up my Core2

Hi,

yesterday I took ten minutes of time to tweak up my Maximus Formula Mobo setting, I was RS at 3850Ghz (480* 8) and I was able to reach 480*8,5 setting Vcore to 1,4V and PPL to 1.60V, here’s the screenshot.

Posted by: advapi | July 10, 2008

Spazio belle donne!

Ciao a tutti, da oggi ho deciso di aprire una nuova sezione, dedicata alle belle donne……cominciamo con questa….

Posted by: advapi | July 9, 2008

Mario’s corner (1)

A little boy was in his room playing with himself, when his father walked in.
“Son  If you masturbate too much, you’re gonna go blind “
“Dad,” the boy said, “I’m over here.”

Posted by: advapi | July 6, 2008

Depeche mode - Suffer Well

Where were you when I fell from grace
Frozen heart, an empty space
Something’s changing, it’s in your eyes
Please don’t speak, you’ll only lie
I found treasure not where I thought
Peace of mind can’t be bought
Still I believe

I just hang on
Suffer well
Sometimes it’s hard
It’s hard to tell

An angel led me when I was blind
I said take me back, I’ve changed my mind
Now I believe
From the blackest room, I was torn
You called my name, our love was born
So I believe

I just hang on
Suffer well
Sometimes it’s hard
It’s hard to tell

I just hang on
Suffer well
Sometimes it’s hard
So hard to tell

Older Posts »

Categories