Tuesday, June 29, 2010

Best Programmer Joke i ve ever heard...


A man flying in a hot air balloon suddenly realizes he’s lost. He reduces height and spots a man down below. He lowers the balloon further and shouts to get directions, "Excuse me, can you tell me where I am?"
The man below says: "Yes. You're in a hot air balloon, hovering 30 feet above this field."
"You must work in Information Technology," says the balloonist.
"I do" replies the man. "How did you know?"
"Well," says the balloonist, "everything you have told me is technically correct, but It's of no use to anyone."
The man below replies, "You must work in management."
"I do," replies the balloonist, "But how'd you know?"
"Well", says the man, "you don’t know where you are, or where you’re going, you expect me to be able to help. You’re in the same position you were before we met, but now it’s my fault."

Tuesday, June 22, 2010

Twitter like alert after form submit in jquery...

Just got my example to work and here it is,



function topBar(message) {
    var $alert = $('<div/>');
    $alert.text(message);
    $alert.click(function() {
        $(this).slideUp(200);
    });
    $(body).append($alert);
    setTimeout(function() { $alert.slideUp(200) }, 5000);
}


and css:


#alert
{
overflow: hidden;
width: 100%;
text-align: center;
position: absolute;
top: 0;
left: 0;
background-color: #FF0000;
height: 0;
color: #FFFFFF;
font: 20px/40px arial, sans-serif;
opacity: .9;
}


Try it and let me know for doubts...

Monday, June 21, 2010

Fluent NHibernate configuration (Ms Sql Server 2005 & Mysql)..


NHibernate is popular in Open-source community, fully featured, mature ORM but the way to config mappings in XML files (.hbm.xml files) is not comfort.
I would prefer to write mappings in strongly typed C# code and enjoy from easy refactoring, improved readability and more concise code.

Fluent NHibernate resolves this issue and provides alternative to NHibernate's standard XML mapping files - fluent, XML-less, compile safe.

Samples of mappings:
public class CustomerMap : ClassMap<Customer>
{
    public CustomerMap()
    {
        WithTable("Customers");
 
        Id(x => x.Id, "CustomerId");
        Map(x => x.Firstname);
        Map(x => x.Lastname);
        Map(x => x.Email, "EmailAddress");
    }
}
 
//For sql server2005
Fluently.Configure()
  .Database(MsSqlConfiguration.MsSql2005
    .ConnectionString(c => c
      .FromAppSetting("connectionString"))
    .Cache(c => c
      .UseQueryCache()
      .ProviderClass<HashtableCacheProvider>())
    .ShowSql())
  .Mappings(m => m
    .FluentMappings.AddFromAssemblyOf<Customer>())
  .BuildSessionFactory();
//For Mysql
Fluently.Configure()
.Database(MySqlConfiguration.Standard
.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")))     .Mappings(m => m.FluentMappings.AddFromAssemblyOf())     .BuildSessionFactory()) 

Always looking forward to maintain whole schema of a database is really challenging..

Getting started with GPS and IVR integration with asp.net mvc...

 I was going through some articles about IVR(Interactive voice response) and GPS(Global positioning system)... I just loved the concept and started to find API's for each... Looking forward to face the challenge...

Thursday, June 17, 2010

When to choose ORM as data access instead of ADO.NET?

I mentioned that I think that hand rolled data access layers using stored procedures are a bad thing, and one of my co-workers asked me to elaborate.

The main reason that I don’t like hand rolled data access layers is that by writing your own DAL, you are basically reimplementing a solved problem. Think about all of the things you have worry about if you write your own DAL:
  • Creating the CRUD stored procs
  • Writing ADO.NET code to call the stored procs
  • Figuring out which entities are dirty and need to be saved, and which properties have changed
  • What relationships do you load when you load an entity from the database? How do you do lazy loading of relationships?
  • Writing tests to test all of this custom code that you have to write
There are numerous object-relational mapping (ORM) tools out there which take care of all of this. NHibernate is my favorite (more specifically, Fluent NHibernate). NHibernate has been around for several years and is very mature. There are ORMs from Microsoft (LINQ to SQL, Entity Framework), and numerous other ORMs out there.
These ORMs have thousands of people using them, so they have been well tested and have proven over time to be very effective at what they do. Countless hours have gone into the development, design, and testing of these ORMs.

Think about what you are trying to do by writing your own hand rolled data access layer. Who are you to think that you can do a better job in a short amount of time than the people who developed these mature solutions over several years? Data access is a very complicated thing to try and implement, and some of the most painful code that I’ve ever had to deal with was found in someone’s hand rolled data access layer.

Here’s the thing — a large percentage of your data access is vanilla loading and saving of objects from the database. In these cases, performance is not a concern and you do not need any special queries in order to optimize the loading and saving of these objects.

For a very small percentage of your data access, performance may be a concern and you may need to use custom stored procedures. So in these cases, you can bypass the ORM and write your stored procedures and custom code in order to optimize the loading and saving of these specific objects.

If you use stored procedures and custom code, you have more control over things. This also comes with a cost (longer time to develop). If you are accepting this cost for cases where you don’t need to optimize the data access, I would say that you’ve wasted time on premature optimization, not to mention that you’ve probably had to spend time implementing all of that data access code.

I would rather use an ORM that has implemented everything that is difficult about data access. Now all I have to tell it how to map to the database (which isn’t that hard) and tell it to do things for me. With lazy loading, it won’t load entity relationships (e.g. child collections on an entity object) unless it needs to. It knows when objects are dirty and if they need to be saved or not. I have an easy hook so that I can validate entities when they are saved.

The other day I configured a cache in NHibernate in 15 minutes. With very little code I was able to set NHibernate up so that it will cache entities that don’t ever change in memory so that it doesn’t have to get to the database to get them every time. There were numerous examples on the internet telling me how to do this, and I’m extremely confident that it’s going to work (I didn’t have to write any of the difficult code for caching because NHibernate has solved that problem).

I want to write code that solves business problems. Thankfully other people have written libraries that will help me do that. So I’m going to use them.

Thursday, June 10, 2010

Fluent nHibernate rocks with asp.net MVC...

Just got my asp.net mvc web application to work with fluent Nhibernate... Just loved the way it ships with asp.net MVC... Looking forward to the challenges when deploying it to live server......

Saturday, June 5, 2010

"Remember the Milk" really rocks my work schedule...

Remember the milk really rocks my work schedule.... I got started with it a week ago and its looks really cool... Guys give a try....