views:

50

answers:

1

I have the below LINQ Query that I would like to suppliment with the Nurse Names. Unfortunately these are stored in a seperate DB and thus a seperate DataContext.

How would I go about calling a method in my aspnetdbcontext from this query, which uses cmodatacontext?

This is the method in aspnetdb to get a nurse's name:

    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;
    }

This is the method in CMO that I call to bind to a 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;
    }

How can I work the two together?

Thanks!

A: 

You just need to create two DataContext objects, retrieve the data in an object in the first data context, and copy that data to a new object in the other data context and SubmitChanges().

Robert Harvey