AsEnumerable
force the Join
statement execution into LINQ to Objects. So all data from RC_CampaignHubSpokeTbl
and RC_CampaignTbl
will be taken from WCF, and then combined together within your application.
It's necessary because WCF calls do not support joins.
To optimize your query a bit you can do following:
que = From CHS In ent.RC_CampaignHubSpokeTbl.AsEnumerable()
Join Cam In ent.RC_CampaignTbl.Where(Function(c) c.tintStatus.Equals(1)).AsEnumerable() On Cam.intCampaign Equals CHS.intCampaign
Select New With {CHS.intCampaign,
CHS.intCouponRefHub,
CHS.intCouponRefSpoke,
CHS.intHubRef,
CHS.intSpokeRef}
Further possible optimization - not sure Contains()
is available in WCF calls, so you have to check it by yourself.
Dim compains = ent.RC_CampaignTbl.Where(Function(c) c.tintStatus.Equals(1)).ToArray()
Dim HubSpokes = ent.RC_CampaignHubSpokeTbl.Where(Function(h) compains.Contains(h.intCampaign)).ToArray()
que = From CHS In compains
Join Cam In HubSpokes On Cam.intCampaign Equals CHS.intCampaign
Select New With {CHS.intCampaign,
CHS.intCouponRefHub,
CHS.intCouponRefSpoke,
CHS.intHubRef,
CHS.intSpokeRef}