コード例 #1
0
        public void EntityType_BaseTypes_Works()
        {
            // Arrange
            ODataModelBuilder builder = GetMockVehicleModel();

            EntityTypeConfiguration sportbike = builder.StructuralTypes
                                                .OfType <EntityTypeConfiguration>().Single(e => e.Name == "sportbike");

            // Act & Assert
            Assert.Equal(
                new[] { "vehicle", "motorcycle" }.OrderBy(name => name),
                sportbike.BaseTypes().Select(e => e.Name).OrderBy(name => name));
        }
コード例 #2
0
        private static void AddOptimisticConcurrencyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                               NavigationSourceConfiguration navigationSourceConfiguration, EdmTypeMap edmTypeMap)
        {
            EntityTypeConfiguration entityTypeConfig = navigationSourceConfiguration.EntityType;

            IEnumerable <StructuralPropertyConfiguration> concurrencyProperties =
                entityTypeConfig.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken);

            foreach (var baseType in entityTypeConfig.BaseTypes())
            {
                concurrencyProperties = concurrencyProperties.Concat(
                    baseType.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken));
            }

            IList <IEdmStructuralProperty> edmProperties = new List <IEdmStructuralProperty>();

            foreach (StructuralPropertyConfiguration property in concurrencyProperties)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    var item = value as IEdmStructuralProperty;
                    if (item != null)
                    {
                        edmProperties.Add(item);
                    }
                }
            }

            if (edmProperties.Any())
            {
                IEdmCollectionExpression collectionExpression = new EdmCollectionExpression(edmProperties.Select(p => new EdmPropertyPathExpression(p.Name)).ToArray());
                IEdmTerm term = Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel.ConcurrencyTerm;
                EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(target, term, collectionExpression);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }