I have this linq query that returns the revenue associated with every colorwaysid present within the given dates but it throws the SQLException:
the specified linq expression contains references to queries that are associated with different context
using (var eshaktiDb = new eshaktiEntities())
{
using (var corpDb = new eshakti_corpEntities())
{
var queryResult =
from product in eshaktiDb.Products
join oivs in corpDb.OrderitemvalueSplits on product.ProductId equals oivs.Productid
join order in corpDb.Orders on oivs.Orderid equals order.OrderID
where product.ColorWaysId != null && order.CrDate >= fromDate && order.CrDate <= toDate
group oivs by product.ColorWaysId into g
select new ColorwayReportResponse
{
colorwayId = (int)g.Key,
revenue = (decimal)g.Sum(o => o.ActItemvalue + o.Custom)
};
return queryResult.ToList();
}
}
How to fix this ? Can somebody help me with the query that would fit in, also since the query involves two different databases, how can I get my desired result ?