How do I get started using MicroDal in my web project?

When the class library (microdal.dll) is downloaded and included in the project, you only have to configure the database connection, and you are ready to go. Remember to qualify the connection, with a provider name. Eg.:

<connectionStrings>
    <add name="MyDb" connectionString="data source=|DataDirectory|\cmsdata.s3db;New=true" providerName="System.Data.SQLite"/>
</connectionStrings>


Now You can use MicroDal with manual session management. That means; you specify the name of the connection every time you use a session:

using (var ses = new DataSession("MyDb")){
    var idx = ses.FetchScalar<int>("SELECT @@IDENTITY");
    //.... 
}

Do you want to let MicroDal manage database connection, and thus optimize the use of the connection, simply register the the DataSessionHttpModul in the web.config:
<httpModules>
  <add name="MicroDalSession" type="MicroDal.Context.DataSessionHttpModule, MicroDal"/>
</httpModules>

So are all the functionality of a static property on the Data Session object - Current. You can then simply use the session when you want it - MicroDal closes and cleans up automatically.

Data Binding is now a simple case:

list1.DataSource = DataSession.Current
    .Fetch<Address>(
        "SELECT * FROM Address WHERE id=@1",
        Request["ID"])
   .ToArray();
list1.DataBind();

To use this approach, You need to ensure that there is column-names that correspond to properties of the Address object. If not, You must qualify its SQL search with alias matching the attribute names. The Object should have a constructor with no parameters to be used as a DTO.

Last edited Sep 12, 2012 at 8:15 AM by TheIMan, version 6