Doesn't Work with Stored Procs?

Jul 22, 2014 at 5:23 PM
When I have EFCache configured, my EF functions (stored procs) fail to execute with exception
"Unable to cast object of type 'System.Data.Entity.Core.Common.CommandTrees.DbFunctionCommandTree' to type 'System.Data.Entity.Core.Common.CommandTrees.DbModificationCommandTree'."
Stack trace is:
at EFCache.CommandTreeFacts..ctor(DbCommandTree commandTree)
at EFCache.CachingProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
I'm thinking I can implement my own subclass of CachingProviderServices and override CreateDbCommandDefinition to do ... something. Just thought I'd check here first and see if anyone else has experienced/solved this issue.
Jul 22, 2014 at 5:52 PM
Edited Jul 22, 2014 at 6:20 PM
Actually, looking through the source of CommandTreeFacts.cs, it looks like I'm hitting the branch with the debug assertion:
Debug.Assert(commandTree is DbModificationCommandTree, "Unexpected command tree kind");

By overriding CachingProviderServices.CreateDbCommandDefinition I was able to confirm that my CommandTreeKind is indeed equal to DbCommandTreeKind.Function, so maybe I've got an outdated build?

I have version 1.0.0-beta though, which as far as I can tell should include the Function supported added on May 18th, 2014. Is that not correct?
Jul 22, 2014 at 6:52 PM
Edited Jul 22, 2014 at 10:49 PM
I have confirmed that the beta changeset does not include the stored proc support in CommandTreeFacts.cs. To work around this I have implemented a subclass of CachingProviderServices with the following override of CreateDbCommandDefinition:
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
            if (commandTree.CommandTreeKind == DbCommandTreeKind.Function)
                return this.providerServices.CreateCommandDefinition(providerManifest, commandTree);

            return base.CreateDbCommandDefinition(providerManifest, commandTree);
Seems to work fine, until the next build of EFCache is released...
Jul 23, 2014 at 7:24 AM
I fixed this on Sunday in changeset 5373ac8. The issue is that if a sproc mapped to a CUD operation is invoked you need to invalidate cache for corresponding EntitySets otherwise you will get stale results.