Page 1 of 1

EntityFramework - Documentation would be helpful

Posted: Mon 04 Feb 2013 21:29
by craigd
I am regularly coming up against limitations in the translation between the capabilities of linq and what I can only assume is the limitations of SOQL.

Simple queries such as the one below fail because I presume the query generator cannot translate it to SOQL. I found an enumeration called FilterFlags, that seem to correspond to the Field "Filter" in the SOAP API, but there doesn't seem to be a way to access this, and the documentation doesn't provide any clear insight into what can and what cannot be done in Linq.

var thisWeekForecastGP = entities.DealSizes.Where(d => d.Opportunity__r.Probability >= 70)
.Select(x => new { Category = x.Business_Unit__r.Name, CloseDate = x.Opportunity__r.CloseDate, Margin = x.OneOffGP })
.Where(x => x.CloseDate >= DateTime.Now.Date && x.CloseDate <= DateTime.Now.Date.AddDays(8))
.GroupBy(x => x.Category)
.Select(x => new { Category = x.Key, Value = x.Sum(y => y.Margin) });

System.Data.Entity.Core.EntityCommandCompilationException was unhandled
HResult=-2146232005
Message=An error occurred while preparing the command definition. See the inner exception for details.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
at System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
at System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.CreateCommandDefinition(ObjectContext context, DbQueryCommandTree tree)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, IEnumerable`1 compiledQueryParameters, AliasGenerator aliasGenerator)
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at Test.Program.Main(String[] args) in d:\Dropbox\Projects\SalesIntelligence\Test\Program.cs:line 30
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NotImplementedException
HResult=-2147467263
Message=The method or operation is not implemented.
Source=Devart.Data.Salesforce.Entity
StackTrace:
at Devart.Data.Expressions.a.a.a(DbFunctionExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbFunctionExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbExpression A_0, DbExpression A_1, DbExpressionKind A_2)
at Devart.Data.Expressions.a.a.a(DbComparisonExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbComparisonExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbExpression A_0, DbExpression A_1, DbExpressionKind A_2)
at Devart.Data.Expressions.a.a.a(DbAndExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbAndExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbExpression A_0, DbExpression A_1, DbExpressionKind A_2)
at Devart.Data.Expressions.a.a.a(DbAndExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbAndExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbFilterExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbFilterExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbExpression A_0, String A_1)
at Devart.Data.Expressions.a.a.b(DbExpression A_0, String A_1)
at Devart.Data.Expressions.a.a.a(DbGroupByExpression A_0)
at System.Data.Entity.Core.Common.CommandTrees.DbGroupByExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
at Devart.Data.Expressions.a.a.a(DbExpression A_0, String A_1)
at Devart.Data.Expressions.a.a.b(DbExpression A_0, String A_1)
at Devart.Data.Expressions.a.a.a(DbProjectExpression A_0)
at Devart.Data.Expressions.a.a.a(DbQueryCommandTree A_0)
at Devart.Data.Expressions.a.a(DbQueryCommandTree A_0)
at Devart.Data.Salesforce.Entity.SalesforceEntityProviderServices.a(h A_0, DbCommandTree A_1)
at Devart.Data.Salesforce.Entity.SalesforceEntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
InnerException:

Re: EntityFramework - Documentation would be helpful

Posted: Wed 06 Feb 2013 14:28
by Shalex
craigd wrote:the documentation doesn't provide any clear insight into what can and what cannot be done in Linq.
The following expressions are not currently supported: DbVariableReferenceExpression, DbTreatExpression, DbRelationshipNavigationExpression, DbRefExpression, DbQuantifierExpression, DbOfTypeExpression, DbIsOfExpression, DbRefKeyExpression, DbEntityRefExpression, DbFunctionExpression, DbDerefExpression, DbArithmeticExpression, DbApplyExpression.
craigd wrote:Message=The method or operation is not implemented.
Source=Devart.Data.Salesforce.Entity
Could you please send us a small test project to reproduce the issue in our environment?

Re: EntityFramework - Documentation would be helpful

Posted: Tue 12 Feb 2013 12:07
by craigd
Thanks for the feedback. Knowing which expressions are not supported helps.

I have found it easy to force execution by calling ".ToList()" early in the expression tree, but this often seems to slow down execution considerably.

Is there a preferred method to use in a Linq environment, or is it better to avoid Linq altogether?

Re: EntityFramework - Documentation would be helpful

Posted: Thu 14 Feb 2013 11:47
by Shalex
Please don't use the expressions which are currently not supported.

As a workaround, you can execute SOQL of any complexity via SalesforceCommand.