Russ,
The thing is, in a logical sense, you are already breaking your n-tier
separation in your data layer. If you have a method named
"GetCustomersWi thSpend", then obviously you are going to return customers,
and not something else. If anything, this is a business layer function
which in turn will call the data layer.
If you really want to keep your types out of the data layer, then return
an ArrayList, and then have a proxy/wrapper in the business side, which does
this:
// In business layer.
public static IList<Customer> GetCustomersWit hSpend(Type type, double spend)
{
// Make the call to the data layer.
ArrayList objects = DataLayer.GetCu stomersWithSpen d(type, spend);
// Convert to an IList implementation:
List<Customer> retVal = new List<Customer>( objects.Count);
// Cycle through and add the item.
foreach (object o in objects)
{
// Add to the arraylist.
retVal.Add((Cus tomer) o);
}
// Return.
return retVal;
}
You should use ICollection<T> instead of Collection<T>, since it will be
easier to swap out later (and there is nothing on the implementation which
isn't offered through the interface). Additionally, IList extends
ICollection<T>, and it offers an indexer, as well as being able to support
data binding easier. Because of this, I returned IList<Customer> .
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard. caspershouse.co m
"russ" <ru****@excite. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Hi,
We have stumbled across an issue using the type safe collection
System.Collecti ons.ObjectModel .Collection <T> to retrieve data from our
data layer.
Say we have a customer object and want to get a type safe collection of
all customers who have spend = X
Within our datalayer we would currently have the following method
public static ArrayList GetCustomersWit hSpend(Type type, double spend)
{
// use custom or mapper here
return ObjectSpace.Get Collection(type ,"where spend =" +
spend.ToString( ));
}
However, say we wanted to use a type safe generic collection I guess we
would use this;
public static
System.Collecti ons.ObjectModel .Collection<Cus tomer>(double spend)
{
}
But this would break the n-tier seperation as our datalayer now knows
about the Customer type.
I guess we could still return an ArrayList from the datalayer and then
create the type safe collection in the business tier using the
ArrayList.
Does anyone have any thoughts on this?
Cheers
Russ