Thursday, October 7, 2010

working with SQLite in WPF

You can use SQLite in WPF the same way you would use SQL Server, Oracle or any other database -- via ADO.NET or (better) via an object-relational mapper.  An ORM is probably a better option because a good ORM will handle things like property change notifications (critical for data binding) for you.

The basic technique you are looking for is to define a model which you will load and save via the ORM, and databind your UI to using data binding.  (The full version of this pattern is called model-view-viewmodel or MVVM but as a beginner you probably want to focus on the basics of creating and binding to a domain model first and tackle the more complex aspects of MVVM later.)

For more on SQLite visit http://sqlite.phxsoftware.com/

What is the best ORM for .NET ?


There are lots of very good ORMs approaching the subject with different philosophies.
None are perfect through and all tend to become complex as soon as you stray from their golden path (and sometimes even when you stick to it).
What you should ask yourself when selecting an ORM:
  1. What does it need to do for you?
    If you already have a set of requirements for your application, then you should select the ORM that better matches these rather than an hypothetical 'best'.
  2. Is your data shared or just local?
    A lot of the hairiness in ORM is caused by how they handle concurrency and changes to the data in the database when multiple users are holding a versions of the same data.
    If your datastore is for a single-user, then most ORMs will do a good job. However, ask yourself some hard questions in a multi-user scenario: how is locking handled? What happens when I delete an object? How does it affects other related objects? Is the ORM working close to the metal of the backend or is it caching a lot of data (improving performance at the expense of increasing the risk of staleness).
  3. Is the ORM well adapted for your type of application? A particular ORM may be hard to work with (lots of performance overhead, hard to code) if it's a used in a service or sitting inside a web app. It may on the contrary be great for desktop apps.
  4. Do you have to give up database-specific enhancements?
    ORMs tend to use the lowest-common denominator set of SQL to ensure they work with lots of different database backend.
    All ORMs will compromise on available features (unless they specifically target a single backend) but some will allow you to implement additional behaviours to exploit specific enhancements available in your chosen backend.
    A typical db-specific enhancement is Full-Text search capabilities for instance; make sure your ORM provides you with a way to access these features if you need them.
  5. How does the ORM manages changes in the data model?
    Some can update the DB automatically within a certain measure, other don't do anything and you'll have to do the dirty work yourself; other provide a framework for handling change that lets you control database updates.
  6. Do your mind to couple your application to the ORM's objects or do you prefer to handle POCOs and user an adapter for persistence?
    The former is usually simple to handle but create dependencies on your ORM-specific data objects everywhere, the latter is more flexible, at the cost of a bit more code.
  7. Will you ever need to transfer your objects remotely?
    Not all ORMs are equal when it comes to fetching objects from a remote server, look closely at what is possible or impossible to do. Some are efficient, others not.
  8. Is there someone you can turn to for help?
    Is there good commercial support? How big and active is the community around the project?
    What are the issues existing users are having with the product?
    Do they get quick solutions?
A few ORMs that I looked at:
  • XPO
    From developer Express: is small and simple, code-centric. They use it for their application frameworkeXpressApp.
  • NHibernate
    Is free, but the learning curve is rather steep. Lots of goodies but it's hard to find what is really relevant sometimes in all the fragmented documentation.
  • LLBLGen Pro
    very mature project, not the simplest but a lot of thought has been put into it.
  • Entity Framework
    Still a bit early IMHO. It's promising, but there are some basic stuff that other ORMs provide that are just now being tackled (auto-generating DB from code for instance).
  • DataObject.Net
    Looks promising but is also a bit new to risk an important project on it IMHO. Quite active though.
There are many others of course.
You can have a look at the controversial site ORM Battle that lists some performance benchmarks, although you have to be aware that raw speed is not necessarily the most important factor for your project and that the producers of the website is DataObject.Net.

Wednesday, October 6, 2010

What coworker habit do you find most annoying?

As I write this, there's a guy in the office clipping his nails at his desk.
Ques : What personal habits do your coworkers exhibit that drive you nuts and how do you deal with them? Do you quietly stew, adjust your attitude, or approach them about it?

What's your experience with female programmers?

I was going through a programmers Q&A  and i saw this question. Do a read of it http://tinyurl.com/3ayjdt6

Wednesday, September 29, 2010

Sqlite with asp.net MVC

Using Sqlite with asp.net MVC web application
 Visual Studio 2008 integrates Sql server 2008 express nicely into App_Data folder. You just create the database using Server Explorer, and it inserts the connection string into web.config for you. I used it when I worked on my toy project – ToastManager. I finished coding and testing on my machine and deployed it to an integration server which belongs to my SCRUM team.
A problem, as usual, arose on the integration box. My windows login had sysadmin access to my local Sql Server express, but the process that runs ToastManager did not on the box.
I blindly thought that Sql Server express is a stand-alone DB and it can be deployed together with the applicaiton. It was misunderstanding. Sql Server Express is still a server application that needs to be installed on a remote machine. I looked for an alternative and soon found that many people useSqlite.
Sqlite is an open source database and people testify that it is really fast. In order to use with .Net, you need to install System.Data.SQLite, which is another open source ADO.NET provider for SQLite database engine.
Once you download Sqlite, you can use its own command-prompt based tool, but probably, your first reaction is to try to find some GUI management tool. Fortunately, there is one too. It is FireFox Add-on: SQLite Manager.
So, to summarise, you need to have 3 programs to use SQLite. SQLite,System.Data.SQLite, and SQLite Manager.

Just now started my first sample will update you on that in the posts to come in future...

Friday, September 24, 2010

Simple reusable clear form function in asp.net using jquery?

I ve created a function which clears the form without writing much javascript code.



$.fn.clearForm = function() {
return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form') {
        $('td.status', this).empty();
        return $(':input', this).clearForm();
    }
    if (type == 'text' || type == 'password' || tag == 'textarea' || tag ==
                                 'label')
        this.value = '';
    else if (type == 'checkbox' )
        this.checked = false;
    else if (tag == 'select')
        this.selectedIndex = -1;

});
};


and just call this as,



function clearaddform() {
    $("#aspnetForm").clearForm();
  }


and now you can just call clearaddform function from your button.