1
我有一個使用多個DataGridView的WinForm應用程序。 DGV曾經被綁定到舊的SProc的DAL中的DataTables。當我將SProcs轉換爲LINQ時,我原本是在關注套件,但我想知道這是否是「最佳」方式。我應該從LINQ返回DataGridView的SQL
這是我正在做的一個樣本。
internal static CmoDataContext context = new CmoDataContext();
public static DataTable GetAllMembers(Guid workerID)
{
DataTable dataTable;
using (context)
{
var AllEnrollees = from enrollment in context.tblCMOEnrollments
where enrollment.CMOSocialWorkerID == workerID || enrollment.CMONurseID == workerID
select
new
{
enrollment.ADRCReferralID,
enrollment.ClientID,
enrollment.CMONurseID,
enrollment.CMOSocialWorkerID,
enrollment.DisenrollmentDate,
enrollment.DisenrollmentReasonID,
enrollment.EconomicSupportWorkerID,
enrollment.EnrollmentDate
};
dataTable = AllEnrollees.CopyLinqToDataTable();
}
return dataTable;
}
CopyLinqToDataTable()
是一個自定義類,很顯然,一個IEnumerable<T>
轉換成一個DataTable。
這樣做有什麼問題嗎?我應該使用IQueryable嗎?
謝謝
+1 yea,我只是將我的DGV綁定到IList <> – dotjoe 2009-09-24 13:57:47
DataGridView不會通過IListSource接口直接綁定到Linq to SQL圖嗎? – Lazarus 2009-09-24 14:02:29