public void Cannot_create_with_null_argument()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", "T", "Q", entityType);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());
            var parameterBindings = Enumerable.Empty<ModificationFunctionParameterBinding>();
            var rowsAffectedParameter = new FunctionParameter("rows_affected", new TypeUsage(), ParameterMode.Out);
            var resultBindings = Enumerable.Empty<ModificationFunctionResultBinding>();

            Assert.Equal(
                "entitySet",
                Assert.Throws<ArgumentNullException>(
                    () => new ModificationFunctionMapping(
                        null, entityType, function, 
                        parameterBindings, rowsAffectedParameter, resultBindings)).ParamName);

            Assert.Equal(
                "function",
                Assert.Throws<ArgumentNullException>(
                    () => new ModificationFunctionMapping(
                        entitySet, entityType, null,
                        parameterBindings, rowsAffectedParameter, resultBindings)).ParamName);

            Assert.Equal(
                "parameterBindings",
                Assert.Throws<ArgumentNullException>(
                    () => new ModificationFunctionMapping(
                        entitySet, entityType, function,
                        null, rowsAffectedParameter, resultBindings)).ParamName);
        }
        public void Cannot_create_function_if_entity_sets_not_null_an_not_matching_number_of_return_parameters()
        {
            var entitySet = new EntitySet("set", null, null, null, new EntityType("entity", "ns", DataSpace.CSpace));

            Assert.Equal(
                Resources.Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters,
                Assert.Throws<ArgumentException>(
                    () => new EdmFunction(
                              "foo",
                              "bar",
                              DataSpace.CSpace,
                              new EdmFunctionPayload()
                                  {
                                      EntitySets = new[] { entitySet, entitySet },
                                      ReturnParameters =
                                          new[]
                                              {
                                                  new FunctionParameter(
                                                      "param",
                                                      TypeUsage.CreateDefaultTypeUsage(
                                                          PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)),
                                                      ParameterMode.ReturnValue)
                                                  ,
                                              }
                                  })).Message);
        }
Esempio n. 3
0
        public void AddEntityTypeMappingFragment(
            EntitySet entitySet, EntityType entityType, MappingFragment fragment)
        {
            Debug.Assert(fragment.Table == Table);

            _entityTypes.Add(entitySet, entityType);

            var defaultDiscriminatorColumn = fragment.GetDefaultDiscriminator();

            foreach (var cm in fragment.ColumnMappings)
            {
                var columnMapping = FindOrCreateColumnMapping(cm.ColumnProperty);
                columnMapping.AddMapping(
                    entityType,
                    cm.PropertyPath,
                    fragment.ColumnConditions.Where(cc => cc.Column == cm.ColumnProperty),
                    defaultDiscriminatorColumn == cm.ColumnProperty);
            }

            // Add any column conditions that aren't mapped to properties
            foreach (
                var cc in
                    fragment.ColumnConditions.Where(cc => fragment.ColumnMappings.All(pm => pm.ColumnProperty != cc.Column)))
            {
                var columnMapping = FindOrCreateColumnMapping(cc.Column);
                columnMapping.AddMapping(entityType, null, new[] { cc }, defaultDiscriminatorColumn == cc.Column);
            }
        }
        // <summary>
        // Add a new entry to the entityTypeToSet map
        // </summary>
        // <param name="entityType"> entity type </param>
        // <param name="entitySet"> entityset producing this type </param>
        private void AddEntityTypeToSetEntry(md.EntityType entityType, md.EntitySet entitySet)
        {
            md.EntitySet other;
            var          rootType           = GetRootType(entityType);
            var          hasSingleEntitySet = true;

            if (entitySet == null)
            {
                hasSingleEntitySet = false;
            }
            else if (m_entityTypeToEntitySetMap.TryGetValue(rootType, out other))
            {
                if (other != entitySet)
                {
                    hasSingleEntitySet = false;
                }
            }

            if (hasSingleEntitySet)
            {
                m_entityTypeToEntitySetMap[rootType] = entitySet;
            }
            else
            {
                m_entityTypeToEntitySetMap[rootType] = null;
            }
        }
        public void PrimaryParameterBindings_should_omit_original_value_parameters_when_update()
        {
            var entitySet = new EntitySet();
            entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            var storageModificationFunctionMapping
                = new StorageModificationFunctionMapping(
                    entitySet,
                    new EntityType("E", "N", DataSpace.CSpace),
                    new EdmFunction("F", "N", DataSpace.SSpace),
                    new[]
                        {
                            new StorageModificationFunctionParameterBinding(
                                new FunctionParameter(),
                                new StorageModificationFunctionMemberPath(
                                new EdmMember[]
                                    {
                                        new EdmProperty("M")
                                    },
                                null),
                                false)
                        },
                    null,
                    null);

            var storageEntityTypeModificationFunctionMapping
                = new StorageEntityTypeModificationFunctionMapping(
                    new EntityType("E", "N", DataSpace.CSpace),
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping);

            Assert.Equal(2, storageEntityTypeModificationFunctionMapping.PrimaryParameterBindings.Count());
        }
        public void Can_retrieve_properties()
        {
            var source = new EntityType("Source", "N", DataSpace.CSpace);
            var target = new EntityType("Target", "N", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var associationType 
                = AssociationType.Create(
                    "AT",
                    "N",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    null,
                    null);
            var sourceSet = new EntitySet("SourceSet", "S", "T", "Q", source);
            var targetSet = new EntitySet("TargetSet", "S", "T", "Q", target);
            var associationSet
                = AssociationSet.Create(
                    "AS",
                    associationType,
                    sourceSet,
                    targetSet,
                    null);

            var members = new List<EdmMember> { null, targetEnd };
            var memberPath = new ModificationFunctionMemberPath(members, associationSet);

            Assert.Equal(members, memberPath.Members);
            Assert.Equal(targetEnd.Name, memberPath.AssociationSetEnd.Name);
        }
        public void Can_not_create_composable_function_import_mapping_with_entity_set_and_null_structural_type_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", null, null, null, entityType);

            var functionImport =
                new EdmFunction(
                    "f",
                    "entityModel",
                    DataSpace.CSpace,
                    new EdmFunctionPayload
                        {
                            IsComposable = true,
                            EntitySets = new[] { entitySet },
                            ReturnParameters =
                                new[]
                                    {
                                        new FunctionParameter(
                                            "ReturnType", 
                                            TypeUsage.CreateDefaultTypeUsage(entityType), 
                                            ParameterMode.ReturnValue)
                                    }
                        });

            Assert.Equal(
                Strings.ComposableFunctionImportsReturningEntitiesNotSupported,
                Assert.Throws<NotSupportedException>(
                    () => new FunctionImportMappingComposable(
                              functionImport,
                              new EdmFunction(
                              "f", "store", DataSpace.CSpace, new EdmFunctionPayload { IsComposable = true }),
                              null)).Message);
        }
Esempio n. 8
0
        public void Configure_should_call_configure_function_configurations()
        {
            var modificationFunctionsConfiguration = new ModificationFunctionsConfiguration();

            var mockModificationFunctionConfiguration = new Mock<ModificationFunctionConfiguration>();

            modificationFunctionsConfiguration.Insert(mockModificationFunctionConfiguration.Object);
            modificationFunctionsConfiguration.Update(mockModificationFunctionConfiguration.Object);
            modificationFunctionsConfiguration.Delete(mockModificationFunctionConfiguration.Object);

            var entitySet = new EntitySet();
            entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            var storageModificationFunctionMapping
                = new StorageModificationFunctionMapping(
                    entitySet,
                    new EntityType("E", "N", DataSpace.CSpace),
                    new EdmFunction("F", "N", DataSpace.SSpace),
                    new StorageModificationFunctionParameterBinding[0],
                    null,
                    null);

            modificationFunctionsConfiguration.Configure(
                new StorageEntityTypeModificationFunctionMapping(
                    new EntityType("E", "N", DataSpace.CSpace),
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping),
                ProviderRegistry.Sql2008_ProviderManifest);

            mockModificationFunctionConfiguration
                .Verify(
                    m => m.Configure(storageModificationFunctionMapping, It.IsAny<DbProviderManifest>()),
                    Times.Exactly(3));
        }
        public void Can_clear_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);

            var entitySetMapping =
                new StorageEntitySetMapping(
                    entitySet,
                    new StorageEntityContainerMapping(container));

            var functionMapping =
                new StorageModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<StorageModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new StorageEntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Equal(1, entitySetMapping.ModificationFunctionMappings.Count());

            entitySetMapping.ClearModificationFunctionMappings();

            Assert.Equal(0, entitySetMapping.ModificationFunctionMappings.Count());
        }
        public void WriteMappingFragment_should_write_store_entity_set_name()
        {
            var fixture = new Fixture();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", null, null, entityType);
            var entityContainer = new EntityContainer("EC", DataSpace.SSpace);

            entityContainer.AddEntitySetBase(entitySet);

            var storageEntitySetMapping
                = new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(entityContainer));

            TypeMapping typeMapping = new EntityTypeMapping(storageEntitySetMapping);

            var mappingFragment = new MappingFragment(entitySet, typeMapping, false);

            fixture.Writer.WriteMappingFragmentElement(mappingFragment);

            Assert.Equal(
                @"<MappingFragment StoreEntitySet=""ES"" />",
                fixture.ToString());
        }
Esempio n. 11
0
        private Dictionary <System.Reflection.PropertyInfo, RelationshipType> GetNavigationProperties(DbContext context, Type entityType)
        {
            Dictionary <System.Reflection.PropertyInfo, RelationshipType> properties = new Dictionary <System.Reflection.PropertyInfo, RelationshipType>();
            MethodInfo   method  = typeof(System.Data.Entity.Core.Objects.ObjectContext).GetMethod("CreateObjectSet", Type.EmptyTypes);
            MethodInfo   generic = method.MakeGenericMethod(entityType);
            var          set     = generic.Invoke(context.GetObjectContext(), null);
            PropertyInfo pi      = set.GetType().GetProperty("EntitySet");

            System.Data.Entity.Core.Metadata.Edm.EntitySet es = (System.Data.Entity.Core.Metadata.Edm.EntitySet)pi.GetValue(set);
            var entitySetElementType = es.ElementType;

            foreach (var navigationProperty in entitySetElementType.NavigationProperties)
            {
                RelationshipType type = RelationshipType.One;

                if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
                    navigationProperty.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
                {
                    type = RelationshipType.ManyToMany;
                }
                else if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
                         navigationProperty.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One)
                {
                    type = RelationshipType.OneToMany;
                }

                properties.Add(entityType.GetProperty(navigationProperty.Name), type);
            }
            return(properties);
        }
 /// <summary>
 ///     Helper method to get the table name for the given s-space <see cref="EntitySet" />.
 /// </summary>
 /// <param name="modelTable">The s-space entity set for the table.</param>
 /// <returns>The table name.</returns>
 protected virtual string GetTableName(EntitySet modelTable)
 {
     return modelTable.MetadataProperties.Contains("Table")
            && modelTable.MetadataProperties["Table"].Value != null
         ? (string)modelTable.MetadataProperties["Table"].Value
         : modelTable.Name;
 }
        // internal for testing
        internal static EntitySet CloneWithDefiningQuery(EntitySet sourceEntitySet, string definingQuery)
        {
            Debug.Assert(sourceEntitySet != null, "sourceEntitySet != null");
            Debug.Assert(!string.IsNullOrWhiteSpace(definingQuery), "invalid definingQuery");

            var metadataProperties =
                sourceEntitySet.MetadataProperties.Where(p => p.PropertyKind != PropertyKind.System).ToList();

            // these properties make it possible for the designer to track 
            // back these types to their source db objects
            if (sourceEntitySet.Schema != null)
            {
                metadataProperties.Add(
                    StoreModelBuilder.CreateStoreModelBuilderMetadataProperty(
                        SchemaAttributeName,
                        sourceEntitySet.Schema));
            }

            if (sourceEntitySet.Table != null)
            {
                metadataProperties.Add(
                    StoreModelBuilder.CreateStoreModelBuilderMetadataProperty(
                        NameAttributeName,
                        sourceEntitySet.Table));
            }

            return
                EntitySet.Create(
                    sourceEntitySet.Name,
                    null,
                    null,
                    definingQuery,
                    sourceEntitySet.ElementType,
                    metadataProperties);
        }
Esempio n. 14
0
        public void AddEntityTypeMappingFragment(
            EntitySet entitySet, EntityType entityType, StorageMappingFragment fragment)
        {
            Debug.Assert(fragment.Table == Table);

            _entityTypes.Add(entitySet, entityType);

            var defaultDiscriminatorColumn = fragment.GetDefaultDiscriminator();
            StorageConditionPropertyMapping defaultDiscriminatorCondition = null;
            if (defaultDiscriminatorColumn != null)
            {
                defaultDiscriminatorCondition =
                    fragment.ColumnConditions.SingleOrDefault(cc => cc.ColumnProperty == defaultDiscriminatorColumn);
            }

            foreach (var pm in fragment.ColumnMappings)
            {
                var columnMapping = FindOrCreateColumnMapping(pm.ColumnProperty);
                columnMapping.AddMapping(
                    entityType,
                    pm.PropertyPath,
                    fragment.ColumnConditions.Where(cc => cc.ColumnProperty == pm.ColumnProperty),
                    defaultDiscriminatorColumn == pm.ColumnProperty);
            }

            // Add any column conditions that aren't mapped to properties
            foreach (
                var cc in
                    fragment.ColumnConditions.Where(cc => !fragment.ColumnMappings.Any(pm => pm.ColumnProperty == cc.ColumnProperty)))
            {
                var columnMapping = FindOrCreateColumnMapping(cc.ColumnProperty);
                columnMapping.AddMapping(entityType, null, new[] { cc }, defaultDiscriminatorColumn == cc.ColumnProperty);
            }
        }
        public void Configure_association_set_should_call_configure_function_configurations()
        {
            var modificationFunctionsConfiguration = new ModificationFunctionsConfiguration();

            var mockModificationFunctionConfiguration = new Mock<ModificationFunctionConfiguration>();

            modificationFunctionsConfiguration.Insert(mockModificationFunctionConfiguration.Object);
            modificationFunctionsConfiguration.Delete(mockModificationFunctionConfiguration.Object);

            var entitySet = new EntitySet();
            entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            var storageModificationFunctionMapping
                = new StorageModificationFunctionMapping(
                    entitySet,
                    new EntityType("E", "N", DataSpace.CSpace),
                    new EdmFunction("F", "N", DataSpace.SSpace),
                    new StorageModificationFunctionParameterBinding[0],
                    null,
                    null);

            modificationFunctionsConfiguration.Configure(
                new StorageAssociationSetModificationFunctionMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping));

            mockModificationFunctionConfiguration
                .Verify(m => m.Configure(storageModificationFunctionMapping), Times.Exactly(2));
        }
        public void Can_get_and_set_ends_via_wrapper_properties()
        {
            var associationType
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)),
                          TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace))
                      };

            var associationSet = new AssociationSet("A", associationType);

            Assert.Null(associationSet.SourceSet);
            Assert.Null(associationSet.TargetSet);

            var sourceEntitySet = new EntitySet();

            associationSet.SourceSet = sourceEntitySet;

            var targetEntitySet = new EntitySet();

            associationSet.TargetSet = targetEntitySet;

            Assert.Same(sourceEntitySet, associationSet.SourceSet);
            Assert.Same(targetEntitySet, associationSet.TargetSet);
        }
        public void Add(EntitySet entitySet, EntityType entityType)
        {
            DebugCheck.NotNull(entitySet);
            DebugCheck.NotNull(entityType);

            var i = 0;

            List<EntityType> entityTypes;
            if (!_entityTypes.TryGetValue(entitySet, out entityTypes))
            {
                entityTypes = new List<EntityType>();
                _entityTypes.Add(entitySet, entityTypes);
            }

            for (; i < entityTypes.Count; i++)
            {
                if (entityTypes[i] == entityType)
                {
                    return;
                }
                else if (entityType.IsAncestorOf(entityTypes[i]))
                {
                    break;
                }
            }
            entityTypes.Insert(i, entityType);
        }
        public void Can_get_entity_set()
        {
            var entityContainerMapping = new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace));
            var entitySet = new EntitySet();
            var entitySetMapping = new StorageEntitySetMapping(entitySet, entityContainerMapping);

            Assert.Same(entitySet, entitySetMapping.EntitySet);
        }
Esempio n. 19
0
 private void AppendDropTable(EntitySet entitySet)
 {
     AppendObjectExistenceCheck(GetQuotedTableNameWithSchema(entitySet), "U");
     AppendSql(" drop table ");
     AppendTableName(entitySet);
     AppendSql(";");
     AppendNewLine();
 }
Esempio n. 20
0
        // ObjectStateEntry will not be detached and creation will be handled from ObjectStateManager
        internal ObjectStateEntry(ObjectStateManager cache, EntitySet entitySet, EntityState state)
        {
            DebugCheck.NotNull(cache);

            _cache = cache;
            _entitySet = entitySet;
            _state = state;
        }
        public void Can_get_and_set_configuration_annotation()
        {
            var entitySet = new EntitySet();

            entitySet.SetConfiguration(42);

            Assert.Equal(42, entitySet.GetConfiguration());
        }
 /// <summary>
 /// Construct a new Mapping Fragment object
 /// </summary>
 /// <param name="tableExtent"></param>
 /// <param name="typeMapping"></param>
 internal StorageMappingFragment(EntitySet tableExtent, StorageTypeMapping typeMapping, bool distinctFlag)
 {
     Debug.Assert(tableExtent != null, "Table should not be null when constructing a Mapping Fragment");
     Debug.Assert(typeMapping != null, "TypeMapping should not be null when constructing a Mapping Fragment");
     m_tableExtent = tableExtent;
     m_typeMapping = typeMapping;
     m_isSQueryDistinct = distinctFlag;
 }
        // ObjectStateEntry will not be detached and creation will be handled from ObjectStateManager
        internal ObjectStateEntry(ObjectStateManager cache, EntitySet entitySet, EntityState state)
        {
            Contract.Requires(cache != null);

            _cache = cache;
            _entitySet = entitySet;
            _state = state;
        }
        /// <summary>
        ///     Construct a EntitySet mapping object
        /// </summary>
        /// <param name="extent"> EntitySet metadata object </param>
        /// <param name="entityContainerMapping"> The entity Container Mapping that contains this Set mapping </param>
        public StorageEntitySetMapping(EntitySet extent, StorageEntityContainerMapping entityContainerMapping)
            : base(extent, entityContainerMapping)
        {
            Check.NotNull(extent, "extent");

            m_modificationFunctionMappings = new List<StorageEntityTypeModificationFunctionMapping>();
            m_implicitlyMappedAssociationSetEnds = new List<AssociationSetEnd>();
        }
        public bool Contains(EntitySet entitySet, EntityType entityType)
        {
            DebugCheck.NotNull(entitySet);
            DebugCheck.NotNull(entityType);

            List<EntityType> setTypes;
            return _entityTypes.TryGetValue(entitySet, out setTypes) && setTypes.Contains(entityType);
        }
        /// <summary>
        ///     Constructs processor based on the contents of a change node.
        /// </summary>
        /// <param name="table"> Table for which changes are being processed. </param>
        internal TableChangeProcessor(EntitySet table)
        {
            DebugCheck.NotNull(table);

            m_table = table;

            // cache information about table key
            m_keyOrdinals = InitializeKeyOrdinals(table);
        }
        private readonly List<RelProperty> m_relProperties; // list of relationship properties for which we have values

        #endregion

        #region constructors

        internal NewEntityBaseOp(OpType opType, TypeUsage type, bool scoped, EntitySet entitySet, List<RelProperty> relProperties)
            : base(opType, type)
        {
            Debug.Assert(scoped || entitySet == null, "entitySet cann't be set of constructor isn't scoped");
            DebugCheck.NotNull(relProperties);
            m_scoped = scoped;
            m_entitySet = entitySet;
            m_relProperties = relProperties;
        }
        public void Create_throws_argument_exception_when_called_with_null_or_empty_arguments()
        {
            var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var associationType =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    Enumerable.Empty<MetadataProperty>());
            var sourceSet = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            // name is null
            Assert.Throws<ArgumentException>(
                () => AssociationSet.Create(
                    null,
                    associationType,
                    sourceSet,
                    targetSet,
                    new [] { metadataProperty }));

            // name is empty
            Assert.Throws<ArgumentException>(
                () => AssociationSet.Create(
                    String.Empty,
                    associationType,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));

            // type is null
            Assert.Throws<ArgumentNullException>(
                () => AssociationSet.Create(
                    "AssociationSet",
                    null,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));
        }
Esempio n. 29
0
        /// <summary>
        /// Creates a MappingFragment instance.
        /// </summary>
        /// <param name="storeEntitySet">The EntitySet corresponding to the table of view being mapped.</param>
        /// <param name="typeMapping">The TypeMapping that contains this MappingFragment.</param>
        /// <param name="makeColumnsDistinct">Flag that indicates whether to include 'DISTINCT' when generating queries.</param>
        public MappingFragment(EntitySet storeEntitySet, TypeMapping typeMapping, bool makeColumnsDistinct)
        {
            Check.NotNull(storeEntitySet, "storeEntitySet");
            Check.NotNull(typeMapping, "typeMapping");

            m_tableExtent = storeEntitySet;
            m_typeMapping = typeMapping;
            m_isSQueryDistinct = makeColumnsDistinct;
        }
        public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata), memberInfo)
        {
            Contract.Requires(entityKey != null);
            Contract.Requires(entitySet != null);

            _entityKey = entityKey;
            ValidateEntityType(entitySet);
        }
        /// <summary>
        ///     Construct a new Mapping Fragment object
        /// </summary>
        public StorageMappingFragment(EntitySet tableExtent, StorageTypeMapping typeMapping, bool isSQueryDistinct)
        {
            Check.NotNull(tableExtent, "tableExtent");
            Check.NotNull(typeMapping, "typeMapping");

            m_tableExtent = tableExtent;
            m_typeMapping = typeMapping;
            m_isSQueryDistinct = isSQueryDistinct;
        }
        public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata), memberInfo)
        {
            Check.NotNull(entityKey, "entityKey");
            Check.NotNull(entitySet, "entitySet");

            _entityKey = entityKey;
            ValidateEntityType(entitySet);
        }
        internal int GetEntitySetId(md.EntitySet e)
        {
            var result = 0;

            if (!m_entitySetToEntitySetIdMap.TryGetValue(e, out result))
            {
                PlanCompiler.Assert(false, "no such entity set?");
            }
            return(result);
        }
Esempio n. 34
0
        // Gets the primary key fields for an entity type.
        public static IEnumerable <PropertyInfo> GetKeysFor(this DbContext db, Type entityType)
        {
            var        objectContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext;
            MethodInfo m             = objectContext.GetType().GetMethod("CreateObjectSet", new Type[] { });
            MethodInfo generic       = m.MakeGenericMethod(entityType);
            object     set           = generic.Invoke(objectContext, null);

            PropertyInfo entitySetPI = set.GetType().GetProperty("EntitySet");

            System.Data.Entity.Core.Metadata.Edm.EntitySet entitySet = (System.Data.Entity.Core.Metadata.Edm.EntitySet)entitySetPI.GetValue(set, null);

            foreach (string name in entitySet.ElementType.KeyMembers.Select(k => k.Name))
            {
                yield return(entityType.GetProperty(name));
            }
        }
 internal ObjectStateEntry(ObjectStateManager cache, System.Data.Entity.Core.Metadata.Edm.EntitySet entitySet, EntityState state)
 {
     this._cache     = cache;
     this._entitySet = (EntitySetBase)entitySet;
     this._state     = state;
 }