I have created a query for testing in LinqPad, I do not think the query is anything special, but it does execute a function stored in the database.
I have included the query here:
var opps = (from o in Entities.Table1
join oa in Entities.Table2 on o.Id equals oa.Table1Id
where (o.StatusId == 1)
&& oa.UserId == userId
select new
{
ID = o.Id,
Options = Entities.GetOptions(o.Id),
LastUpdated = o.UpdatedDate
}).ToList();
Now, running this within LinqPad, no errors are produced, but if I run the same code within a function in my c# project I get the following error message.
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[Dal.GetOptionsReturnModel] GetOptions(System.Nullable`1[System.Int64])' method, and this method cannot be translated into a store expression.
Commenting out the line:
*Options = Entities.GetOptions(o.Id),*
Fixes the problem, so I know it is to do with this, but I cannot figure out why it works in LinqPad.
Update
GetOptions is a function within the sql server database.
Update 2
Thanks for the replies, I did notice that I did not place the error on this question. Right to rectify that now.
The original error message was
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[Dal.GetOptionsReturnModel] GetOptions(System.Nullable`1[System.Int64])' method, and this method cannot be translated into a store expression.
After applying the IEnumerable, the error changes to:
"System.Data.Entity.Core.EntityCommandExecutionException",
"An error occurred while executing the command definition. See the inner exception for details.",
"There is already an open DataReader associated with this Command which must be closed first.",
" at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)\r\n at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)\r\n
Update 3
Not sure if it helps, but in Visual Studio, I am using EF 6.0.0