When working with Windows Form controls and LINQ is there a "Best Option" for how your Buisiness Layer returns the Data?
Right now I am returning DataTables so that I can then set the DataSource to the returned DataTable. Is there a better option? Why?
public class BLLMatrix
{
public static DataTable GetMaintItems(int iCat)
{
IQueryable<tblCaseNotesMaintItem> tItems = DALMatrix.GetCNTable();
return
(tItems.Where(item => item.CategoryID == iCat & item.IsActive).OrderBy(item => item.OrderID).Select(
item => new { item.ItemID, item.ItemDescription })).CopyLinqToDataTable();
}
internal static class DALMatrix
{
internal static MatrixDataContext MatrixDataContext = new MatrixDataContext();
internal static Table<tblCaseNotesMaintItem> GetCNTable()
{
return MatrixDataContext.GetTable<tblCaseNotesMaintItem>();
}
I found this similar question --> Separating concerns with Linq To SQL and DTO's
Personally, I prefer Data Transfer Objects, but DataSets work in a pinch.
Basically, the idea is that if you are working with Data Transfer Objects (which have no logic, and represent the model that you are looking to work with on the client), that is an abstraction that can live on regardless of changes on the front or back end. It's typically a good idea.
DataSets are useful, but their lack of compile-time safety (not in the case of strongly-typed DataSets though) because of numeric/string-based field access can pose a problem.
Typically, there is also a large amount of overhead in serializing DataSets over a wire compared to a Data Transfer Object.