/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public InternalEntityTypeBuilder Apply(InternalEntityTypeBuilder entityTypeBuilder) { EntityType baseEntityType = Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)).Metadata; IEnumerable <Type> knownTypes = baseEntityType.ClrType ?.GetTypeInfo() .GetCustomAttributes <BsonKnownTypesAttribute>(false) .SelectMany(bsonKnownTypeAttribute => bsonKnownTypeAttribute.KnownTypes) .ToList(); MongoDbEntityTypeAnnotations annotations = entityTypeBuilder.MongoDb(); if (!annotations.DiscriminatorIsRequired) { annotations.DiscriminatorIsRequired = baseEntityType.IsAbstract(); } if (knownTypes != null) { InternalModelBuilder modelBuilder = entityTypeBuilder.ModelBuilder; foreach (Type derivedType in knownTypes) { modelBuilder .Entity(derivedType, ConfigurationSource.DataAnnotation) .HasBaseType(baseEntityType, ConfigurationSource.DataAnnotation) .MongoDb() .IsDerivedType = true; } } return(entityTypeBuilder); }
/// <inheritdoc /> public override InternalEntityTypeBuilder Apply( InternalEntityTypeBuilder entityTypeBuilder, BsonKnownTypesAttribute bsonKnownTypesAttribute) { MongoDbEntityTypeAnnotations annotations = entityTypeBuilder.MongoDb(); if (!annotations.DiscriminatorIsRequired) { annotations.DiscriminatorIsRequired = entityTypeBuilder.Metadata.IsAbstract(); } if (bsonKnownTypesAttribute.KnownTypes != null) { InternalModelBuilder modelBuilder = entityTypeBuilder.ModelBuilder; Type baseType = entityTypeBuilder.Metadata.ClrType; foreach (Type derivedType in bsonKnownTypesAttribute.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, ConfigurationSource.DataAnnotation) .MongoDb() .IsDerivedType = true; } } return(entityTypeBuilder); }
/// <inheritdoc /> public override InternalEntityTypeBuilder Apply( InternalEntityTypeBuilder entityTypeBuilder, MongoCollectionAttribute mongoCollectionAttribute) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NotNull(mongoCollectionAttribute, nameof(mongoCollectionAttribute)); entityTypeBuilder.MongoDb().CollectionName = mongoCollectionAttribute.CollectionName; return(entityTypeBuilder); }
public virtual void Apply([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { if (entityTypeBuilder == null) { throw new ArgumentNullException(nameof(entityTypeBuilder)); } entityTypeBuilder .MongoDb(ConfigurationSource.DataAnnotation) .SetIsRootType(true); }
public virtual void Apply([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { if (entityTypeBuilder == null) { throw new ArgumentNullException(nameof(entityTypeBuilder)); } entityTypeBuilder .MongoDb(ConfigurationSource.DataAnnotation) .HasDiscriminator(Discriminator) .SetDiscriminatorIsRequired(entityTypeBuilder.Metadata.IsAbstract()); }
public override InternalEntityTypeBuilder Apply( [NotNull] InternalEntityTypeBuilder entityTypeBuilder, [NotNull] CollectionAttribute attribute) { if (!string.IsNullOrWhiteSpace(attribute.Name)) { entityTypeBuilder.MongoDb(ConfigurationSource.DataAnnotation).HasName(attribute.Name); } return(entityTypeBuilder); }
/// <inheritdoc /> public override InternalEntityTypeBuilder Apply(InternalEntityTypeBuilder entityTypeBuilder, BsonDiscriminatorAttribute attribute) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NotNull(attribute, nameof(attribute)); MongoDbEntityTypeAnnotations annotations = entityTypeBuilder.MongoDb(); if (!string.IsNullOrWhiteSpace(attribute.Discriminator)) { annotations.Discriminator = attribute.Discriminator; } if (!annotations.DiscriminatorIsRequired) { annotations.DiscriminatorIsRequired = attribute.Required; } annotations.IsRootType = attribute.RootClass; return(entityTypeBuilder); }