Showing posts with label Serialization. Show all posts
Showing posts with label Serialization. Show all posts

Thursday, November 11, 2010

How to: Serializable with DAAB

This is how we can convert as Serializable which are written in Data Layer with Enterprise Library DAAB. All you need to do is make the Class and Connection object as Serializable.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Runtime.Serialization;
/// <summary>
/// Summary description for DataLayer
/// </summary>
[Serializable]
public class DataLayer : IDeserializationCallback
{
    [NonSerialized]
    Database db;
    
	public DataLayer()
	{
        db = DatabaseFactory.CreateDatabase("DBConnectionString");        
	}
    public DataTable GetClients()
    {
        DataTable result = new DataTable();
        DbCommand dbcommand = db.GetStoredProcCommand("GetAll_Clients");
        DataSet ds = db.ExecuteDataSet(dbcommand);
        if (ds.Tables.Count > 0)
        {
            result = ds.Tables[0];
            ds = null;
        }
        return result;
    }
    #region IDeserializationCallback Members
    void IDeserializationCallback.OnDeserialization(object sender)
    {
        db = DatabaseFactory.CreateDatabase("DBConnectionString");
    }
    #endregion
}

But you need to make all the data layer classes serializble this way to get the connection right.

Friday, April 30, 2010

Handling large sets of data from WCF service in Silverlight application

I had the problem of handling data which is coming from my WCF web service to Silverlight application. When data is huge i got communication exception. I have googled on this and found a great article to handle huge amount of data.

Here is a great article by Syed Mehroz Alam. I found it very helpful.