我可以从一个 DataContext 中调用另一个 DataContext 中的方法吗?

发布于 2024-08-06 07:00:12 字数 2286 浏览 3 评论 0原文

我有以下 LINQ 查询,我想为其补充护士姓名。不幸的是,它们存储在单独的数据库中,因此也是单独的 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 的 CMO 中的方法:

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

如何将两者结合使用?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2024-08-13 07:00:12

您只需创建两个 DataContext 对象,检索第一个数据上下文中的对象中的数据,然后将该数据复制到另一个数据上下文中的新对象和 SubmitChanges() 中。

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文