示例#1
0
        /// <inheritdoc />
        protected override void ProcessEntityTypeAdded(
            IConventionEntityTypeBuilder entityTypeBuilder,
            BsonKnownTypesAttribute attribute,
            IConventionContext <IConventionEntityTypeBuilder> context)
        {
            MongoEntityTypeAnnotations annotations = entityTypeBuilder.MongoDb();

            if (!annotations.DiscriminatorIsRequired)
            {
                annotations.DiscriminatorIsRequired = entityTypeBuilder.Metadata.IsAbstract();
            }

            if (attribute.KnownTypes != null)
            {
                IConventionModelBuilder modelBuilder = entityTypeBuilder.ModelBuilder;
                Type baseType = entityTypeBuilder.Metadata.ClrType;

                foreach (Type derivedType in attribute.KnownTypes)
                {
                    if (!baseType.IsAssignableFrom(derivedType))
                    {
                        throw new InvalidOperationException($"Known type {derivedType} declared on base type {baseType} does not inherit from base type.");
                    }

                    modelBuilder
                    .Entity(derivedType, fromDataAnnotation: true)
                    .MongoDb()
                    .IsDerivedType = true;
                }
            }
        }
 /// <inheritdoc />
 protected override void ProcessEntityTypeAdded(
     IConventionEntityTypeBuilder entityTypeBuilder,
     TableAttribute attribute,
     IConventionContext <IConventionEntityTypeBuilder> context)
 {
     Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
     Check.NotNull(attribute, nameof(attribute));
     entityTypeBuilder.MongoDb().CollectionName = attribute.Name;
 }
        /// <inheritdoc />
        protected override void ProcessEntityTypeAdded(
            IConventionEntityTypeBuilder entityTypeBuilder,
            BsonDiscriminatorAttribute attribute,
            IConventionContext <IConventionEntityTypeBuilder> context)
        {
            Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
            Check.NotNull(attribute, nameof(attribute));
            MongoEntityTypeAnnotations annotations = entityTypeBuilder.MongoDb();

            if (!string.IsNullOrWhiteSpace(attribute.Discriminator))
            {
                annotations.Discriminator = attribute.Discriminator;
            }

            if (!annotations.DiscriminatorIsRequired)
            {
                annotations.DiscriminatorIsRequired = attribute.Required;
            }

            annotations.IsRootType = attribute.RootClass;
        }