0

I want to create a LINQ to entities query getting data(join) out of two tables and bind the result as datasource to a datagridview.

Unfortunately I seem to stumble upon a syntax issue.

Table 1 : dcpricing.tblpricing Table 2 : dcpropertydetail.tblpropertydetail

Grid: grdpricing

Dim qry = (From propertyobj In dcPropertyDetail.tblproperydetail
                  Join Pricingobj In dcPricing.tblpricing
                  On propertyobj.prop_det_index Equals Pricingobj.prop_id
                  Where (propertyobj.prop_det_Status = 1)
                  Select propertyobj.prop_det_Name,          Pricingobj.prop_rental_double).ToList

grdpricing.datasource = qry

The error pops when passing the query and shows: [COLOR="Red"]The specified LINQ expression contains references to queries that are associated with different contexts.[/COLOR]

I appreciate all help! Stijn

1 Answers1

1

The error message tells you exactly what the problem is - you've got a query that is trying to span data contexts. Specifically, your tblpropertydetail table comes from the dcPropertyDetail data context, and your tblpricing table comes from the dcPricing context. This is not allowed in Entity Framework.

Is there some reason you can't have them in the same data context? If they are in different databases, see this question for a workaround.

Community
  • 1
  • 1
GalacticCowboy
  • 11,663
  • 2
  • 41
  • 66