views:

520

answers:

1

Hi,

I'm using a distributed web application, with a database server housing the SQL Server 2005 database, an application server where we've installed a Microsoft Three Tier Service Application, and a web server where I using MVP with supervising controller.

My service layer, on the application server, returns an IEnumerable<Country> when I request a list of let's say countries. The service layer calls the data access component, which yields entities like this:

public virtual IEnumerable<T> FillList(DbCommand command, DataContext context)
{
    using (IDataReader dataReader = this.ExecuteReader(command, context))
    {
        while (dataReader.Read())
        {
            T entity = this.Fill(dataReader, context);
            yield return entity;
        }
    }
}

I'm now a little bit concerned about the connection to my database, as it will remain open when I serialize entities through WCF to my controller. My first question is if this is really a concern to leave my database connection open when serializing entity by entity to my controller? The advantage of this solution is that I can use LINQ even over large collections (not LINQ to SQL).

I came up with this solution: in the service layer, I always return a List, like this:

public virtual List<T> GetList()
{
    List<T> list = new List<T>();
    list.AddRange(this.dataAccess.GetList()));
    return list;
}

But here I'm returning a full list to the controller, and perhaps I only need a few of the items from the list. My second question is if this is a good design?

Look forward to your suggestions!

A: 

I don't see any particular problems with the design.

Of course, you'll want to be careful about what the T is in List<T>. Don't return a list of objects with all sorts of behaviors, and don't return types specific to .NET - DataSet and DataTable are a bad idea, for instance. Use simple classes with properties of primitive types, lists and arrays of primitive types, lists and arrays of these simple classes, etc.

John Saunders