c# - Pulling Data from 1 DataContext to use in another's Method -



c# - Pulling Data from 1 DataContext to use in another's Method -

i have been trying convert sql statement linq 1 , having problem fact part of info returned in seperate database(datacontext) rest. pretty sure can overcome seem failing @ accomplishing or finding examples of previous successful attempts.

can offer guidance on overcome hurdle? thanks

select p.personid, p.firstname, p.middlename, p.lastname, cp.enrollmentid, cp.enrollmentdate, cp.disenrollmentdate [connect].dbo.tblperson p inner bring together ( select c.clientid, c.enrollmentid, c.enrollmentdate, c.disenrollmentdate [cmo].dbo.tblcmoenrollment c left outer bring together [cmo].dbo.tblworkerhistory wh on c.enrollmentid = wh.enrollmentid inner bring together [cmo].dbo.tblstaffextended se on wh.worker = se.staffid (wh.enddate null or wh.enddate >= getdate()) , wh.worker = --workerguid param here ) cp on p.personid = cp.clientid order p.personid

i have asked similar question here before told need create view in order accomplish this. still true or ever?

i utilize linqpad lot of linq sql. 1 of features allows utilize of multiple info contexts 1 query.

for instance here code wrote in linqpad

from template in ratetemplates template.policies.any(p => staging_history.changes.any(c => (c.policies.any(cp => cp.policyid == p.policyid) || c.policyfees.any(cpf => cpf.policyid == p.policyid) || c.policyoptions.any(cpo => cpo.policyid == p.policyid)) && c.changetime > new datetime(2012, 1, 11) ) ) select new { templateid = template.id, userid = template.userid, propertyids = template.properties.select(ppty => ppty.propertyid) }

the table "ratetemplates" part of first info context (with linqpad not have define first info context in code assumed, if c# need context utilize etc). "staging_history" sec info context , using table "changes" one.

linq sql sorts of magic in background , resulting sql gets executed ...

-- part parameters declare @p0 datetime = '2012-01-11 00:00:00.000' -- endregion select [t0].[id] [templateid], [t0].[userid], [t1].[propertyid], ( select count(*) [property] [t7] [t7].[ratetemplateid] = [t0].[id] ) [value] [ratetemplate] [t0] left outer bring together [property] [t1] on [t1].[ratetemplateid] = [t0].[id] exists( select null [empty] [policy] [t2] (exists( select null [empty] [staging_history].[dbo].[change] [t3] ((exists( select null [empty] [staging_history].[dbo].[policy] [t4] ([t4].[policyid] = [t2].[policyid]) , ([t4].[changeid] = [t3].[id]) )) or (exists( select null [empty] [staging_history].[dbo].[policyfee] [t5] ([t5].[policyid] = [t2].[policyid]) , ([t5].[changeid] = [t3].[id]) )) or (exists( select null [empty] [staging_history].[dbo].[policyoption] [t6] ([t6].[policyid] = [t2].[policyid]) , ([t6].[changeid] = [t3].[id]) ))) , ([t3].[changetime] > @p0) )) , ([t2].[ratetemplateid] = [t0].[id]) ) order [t0].[id], [t1].[propertyid]

so looks need load 1 info context each database want utilize , build linq query makes utilize of both info contexts in 1 linq statement, have above.

hopefully helps out , gets results wanting without having go creating views each cross context queries want do.

c# linq linq-to-sql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -