我可以从一个 DataContext 中调用另一个 DataContext 中的方法吗?
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需创建两个 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().