2009-09-24 70 views
0

我有以下LINQ查詢,我想用護士姓名來填寫。不幸的是,這些存儲在一個單獨的數據庫中,因此存儲在一個單獨的DataContext中。我可以在另一個DataContext中調用另一個方法嗎?

如何從此查詢調用我的aspnetdbcontext中的方法,該查詢使用cmodatacontext

這是aspnetdb的方法來獲得一個護士的名字:

internal static AspnetdbDataContext context = new AspnetdbDataContext(); 

    public static IList WorkerList(Guid userID) 
    { 
     IList theWorkers; 
     using (context) 
     { 
      var workers = from user in context.tblDemographics 
          where user.UserID == userID 
          select new { user.FirstName, user.LastName, user.Phone }; 
      theWorkers = workers.ToList(); 
     } 
     return theWorkers; 
    } 

這是奇美電子的方法,我稱之爲綁定到一個DataGridView:

public static DataTable GetAllMembers(Guid workerID) 
    { 
     DataTable dataTable; 

     using (context) 
     { 
      var AllEnrollees = from enrollment in context.tblCMOEnrollments 
           where enrollment.CMOSocialWorkerID == workerID || enrollment.CMONurseID == workerID 
           from supportWorker in context.tblSupportWorkers 
           where supportWorker.SupportWorkerID == enrollment.EconomicSupportWorkerID 
           select 
            new 
             { 
              enrollment.ADRCReferralID, 
              enrollment.ClientID, 
              enrollment.CMONurseID, 
              enrollment.CMOSocialWorkerID, 
              enrollment.DisenrollmentDate, 
              enrollment.DisenrollmentReasonID, 
              supportWorker.FirstName, 
              supportWorker.LastName, 
              supportWorker.Phone, 
              enrollment.EnrollmentDate 
             }; 

      dataTable = AllEnrollees.CopyLinqToDataTable(); 
     } 
     return dataTable; 
    } 

如何我可以一起工作嗎?

謝謝!

回答

0

您只需創建兩個DataContext對象,在第一個數據上下文中檢索對象中的數據,並將該數據複製到其他數據上下文和SubmitChanges()中的新對象。

相關問題