Ejemplo n.º 1
0
        public CommandTreeFacts(DbCommandTree commandTree)
        {
            IsQuery = commandTree is DbQueryCommandTree;

            var visitor = new CommandTreeVisitor();

            if (commandTree.CommandTreeKind == DbCommandTreeKind.Function)
            {
                var edmFunction = ((DbFunctionCommandTree)commandTree).EdmFunction;

                var containerMapping =
                    commandTree.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace).GetItems <EntityContainerMapping>().Single();

                var entitySetMappings =
                    containerMapping.EntitySetMappings.Where(
                        esm => esm.ModificationFunctionMappings.Any(
                            mfm => mfm.DeleteFunctionMapping.Function == edmFunction ||
                            mfm.InsertFunctionMapping.Function == edmFunction ||
                            mfm.UpdateFunctionMapping.Function == edmFunction));

                AffectedEntitySets =
                    (from esm in entitySetMappings
                     from etm in esm.EntityTypeMappings
                     from mappingFragment in etm.Fragments.Where(f => f.StoreEntitySet != null)
                     select mappingFragment.StoreEntitySet).Cast <EntitySetBase>().ToList().AsReadOnly();
            }
            else
            {
                if (commandTree.CommandTreeKind == DbCommandTreeKind.Query)
                {
                    ((DbQueryCommandTree)commandTree).Query.Accept(visitor);
                }
                else
                {
                    Debug.Assert(commandTree is DbModificationCommandTree, "Unexpected command tree kind");

                    ((DbModificationCommandTree)commandTree).Target.Expression.Accept(visitor);
                }

                AffectedEntitySets            = new ReadOnlyCollection <EntitySetBase>(visitor.EntitySets);
                UsesNonDeterministicFunctions =
                    visitor.Functions.Any(f => NonDeterministicFunctions.Contains(
                                              string.Format("{0}.{1}", f.NamespaceName, f.Name)));
            }

            MetadataWorkspace = commandTree.MetadataWorkspace;
        }
Ejemplo n.º 2
0
        public CommandTreeFacts(DbCommandTree commandTree)
        {
            IsQuery = commandTree is DbQueryCommandTree;

            var visitor = new CommandTreeVisitor();

            if (commandTree.CommandTreeKind == DbCommandTreeKind.Function)
            {
                var edmFunction = ((DbFunctionCommandTree)commandTree).EdmFunction;

                var containerMapping =
                    commandTree.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace).GetItems<EntityContainerMapping>().Single();

                var entitySetMappings =
                containerMapping.EntitySetMappings.Where(
                    esm => esm.ModificationFunctionMappings.Any(
                        mfm => mfm.DeleteFunctionMapping.Function == edmFunction ||
                        mfm.InsertFunctionMapping.Function == edmFunction ||
                        mfm.UpdateFunctionMapping.Function == edmFunction));

                AffectedEntitySets =
                    (from esm in entitySetMappings
                    from etm in esm.EntityTypeMappings
                    from mappingFragment in etm.Fragments.Where(f => f.StoreEntitySet != null)
                    select mappingFragment.StoreEntitySet).Cast<EntitySetBase>().ToList().AsReadOnly();
            }
            else
            {
                if (commandTree.CommandTreeKind == DbCommandTreeKind.Query)
                {
                    ((DbQueryCommandTree)commandTree).Query.Accept(visitor);
                }
                else
                {
                    Debug.Assert(commandTree is DbModificationCommandTree, "Unexpected command tree kind");

                    ((DbModificationCommandTree)commandTree).Target.Expression.Accept(visitor);
                }

                AffectedEntitySets = new ReadOnlyCollection<EntitySetBase>(visitor.EntitySets);
                UsesNonDeterministicFunctions =
                    visitor.Functions.Any(f => NonDeterministicFunctions.Contains(
                            string.Format("{0}.{1}", f.NamespaceName, f.Name)));
            }

            MetadataWorkspace = commandTree.MetadataWorkspace;
        }