Why is Linqpad able to run Linq that does not run in c#

Hi, I have a problem, whereby, i cannot get some Linq to run to C#, but it works in Linqpad

https://stackoverflow.com/questions/5873048/linq-different-results-with-linq-to-sql-vs-linqpad

I am sort of having a similar problem, but it is with stored procs.

I have some Linq

var op = (from o in Entities.Opportunities
join c in Entities.Customers on o.CustomerId equals c.CustomerId
join st in Entities.ShipToes on o.ShipToId equals st.ShipToId
join sta in Entities.Addresses on st.AddressId equals sta.AddressId
join x in Entities.Postcodes on sta.PostcodeId equals x.PostCodeId into w from stp in w.DefaultIfEmpty()
join v in Entities.Projects on o.ProjectId equals v.ProjectId into v from pro in w.DefaultIfEmpty()
join oi in Entities.OpportunityAssignments on o.OpportunityId equals oi.OpportunityId
join y in Entities.DurationIntervals on o.DurationIntervalId equals y.DurationIntervalId into x from di in x.DefaultIfEmpty()
where (o.OpportunityStatusId == 1 || o.OpportunityStatusId == 7)
&& (o.IsInIsrQueue == false)
&& (o.OpportunityId == opportunityId)
&& (oi.IsPrimary == true)
//select(o)).FirstOrDefault();
select new
{
Opportunity = o,
opportunityId = o.OpportunityId,
duration = o.DurationValue,
durationPeriod = o.DurationInterval,
majorProjectId = o.ProjectId,
useInGraph = o.IsProjectQuantity,
volume = o.Quantity,
opportunityStatusId = o.OpportunityStatusId,
IsActiveStatus = o.OpportunityStatus.IsActiveStatus,
opportunityReasonId = o.OpportunityLostReasonId,
comments = o.Comment,
competitorId = o.LostToCompetitorId,
sourceId = o.DataSourceId,
GetCrossSellOptionForOpportunity = Entities.GetCrossSellOptionForOpportunity(o.OpportunityId),
projects = Entities.GetOpportunityProjectPaul(o.OpportunityId),
items = Entities.GetOpportunityItemPaul(o.OpportunityId),
lastUpdated = o.UpdatedDate
}).FirstOrDefault();

This works in LinqPad, but fails to run within a C# VS2015 environment.

The error relates to the lines in the select statement

GetCrossSellOptionForOpportunity = Entities.GetCrossSellOptionForOpportunity(o.OpportunityId),
projects = Entities.GetOpportunityProjectPaul(o.OpportunityId),
items = Entities.GetOpportunityItemPaul(o.OpportunityId),

These are either Stored procedures or functions. As an example, GetCrossSellOptionForOpportunity returns an object of type GetOpportunityProjectPaulReturnModel. the context.cs file has the correct settings, and GetOpportunityProjectPaulReturnModel is generated as a class against the context.tt4 file. The app compiles with no errors, but it still crashes


Our database is mapped into c# using the EntityFramework Reverse POCO Generator addin, located here: https://marketplace.visualstudio.com/items?itemName=SimonHughes.EntityFrameworkReversePOCOGenerator

The physical error returned is:

LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[GetOpportunityProjectPaulReturnModel] GetOpportunityProjectPaul(System.Nullable`1[System.Int64])' method, and this method cannot be translated into a store expression.




Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!