private InternalEntityTypeBuilder Entity( TypeIdentity type, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(null); } var clrType = type.Type; var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType == null) { if (clrType == null) { Metadata.Unignore(type.Name); entityType = Metadata.AddEntityType(type.Name, configurationSource); } else { Metadata.Unignore(clrType); entityType = Metadata.AddEntityType(clrType, configurationSource); } } else { entityType.UpdateConfigurationSource(configurationSource); } return(entityType?.Builder); }
private InternalEntityTypeBuilder Entity( TypeIdentity type, string definingNavigationName, EntityType definingEntityType, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(null); } var clrType = type.Type; var dependentEntityType = clrType == null ? Metadata.FindEntityType(type.Name, definingNavigationName, definingEntityType) : Metadata.FindEntityType(clrType, definingNavigationName, definingEntityType); if (dependentEntityType == null) { var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType != null) { if (!configurationSource.Overrides(entityType.GetConfigurationSource())) { return(null); } if (entityType.GetConfigurationSource() != ConfigurationSource.Explicit) { Ignore(entityType, configurationSource); } } if (clrType == null) { Metadata.Unignore(type.Name); dependentEntityType = Metadata.AddEntityType(type.Name, definingNavigationName, definingEntityType, configurationSource); } else { Metadata.Unignore(clrType); dependentEntityType = Metadata.AddEntityType(clrType, definingNavigationName, definingEntityType, configurationSource); } } else { dependentEntityType.UpdateConfigurationSource(configurationSource); } return(dependentEntityType?.Builder); }
public virtual InternalEntityTypeBuilder Entity([NotNull] Type type, ConfigurationSource configurationSource) { return(IsIgnored(type.DisplayName(), configurationSource) ? null : _entityTypeBuilders.GetOrAdd( () => Metadata.FindEntityType(type), () => Metadata.AddEntityType(type), entityType => new InternalEntityTypeBuilder(entityType, ModelBuilder), OnEntityTypeAdded, configurationSource)); }
public virtual InternalEntityTypeBuilder Entity([NotNull] Type type, ConfigurationSource configurationSource) { return(!CanAdd(type.FullName, configurationSource) ? null : _entityTypeBuilders.GetOrAdd( () => Metadata.FindEntityType(type), () => Metadata.AddEntityType(type), entityType => new InternalEntityTypeBuilder(entityType, ModelBuilder), ConventionDispatcher.OnEntityTypeAdded, configurationSource)); }
public virtual InternalEntityBuilder GetOrAddEntity([NotNull] Type type) { Check.NotNull(type, "type"); var entityType = Metadata.TryGetEntityType(type); if (entityType == null) { Metadata.AddEntityType(entityType = new EntityType(type)); EntityTypeAdded(entityType); } return(new InternalEntityBuilder(entityType, ModelBuilder)); }
public virtual InternalEntityBuilder Entity([NotNull] Type type, ConfigurationSource configurationSource) { Check.NotNull(type, "type"); if (!CanAdd(type.FullName, configurationSource)) { return(null); } return(_entityBuilders.GetOrAdd( () => Metadata.TryGetEntityType(type), () => EntityTypeAdded(Metadata.AddEntityType(type)), entityType => new InternalEntityBuilder(entityType, ModelBuilder), configurationSource)); }
public virtual InternalEntityBuilder Entity([NotNull] string name, ConfigurationSource configurationSource) { Check.NotEmpty(name, "name"); if (!CanAdd(name, configurationSource)) { return(null); } return(_entityBuilders.GetOrAdd( () => Metadata.TryGetEntityType(name), () => Metadata.AddEntityType(name), EntityTypeAdded, configurationSource)); }
public virtual InternalEntityTypeBuilder Entity([NotNull] string name, ConfigurationSource configurationSource) { Check.NotEmpty(name, nameof(name)); if (!CanAdd(name, configurationSource)) { return(null); } return(_entityTypeBuilders.GetOrAdd( () => Metadata.FindEntityType(name), () => Metadata.AddEntityType(name), entityType => new InternalEntityTypeBuilder(entityType, ModelBuilder), ConventionDispatcher.OnEntityTypeAdded, configurationSource)); }
public virtual InternalEntityTypeBuilder Entity([NotNull] Type type, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(null); } var entityType = Metadata.FindEntityType(type); if (entityType == null) { Metadata.Unignore(type); entityType = Metadata.AddEntityType(type, configurationSource); } else { entityType.UpdateConfigurationSource(configurationSource); } return(entityType?.Builder); }
/// <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 virtual InternalEntityTypeBuilder Entity([NotNull] string name, ConfigurationSource configurationSource, bool runConventions = true) { if (IsIgnored(name, configurationSource)) { return(null); } var entityType = Metadata.FindEntityType(name); if (entityType == null) { Metadata.Unignore(name); entityType = Metadata.AddEntityType(name, configurationSource, runConventions); } else { entityType.UpdateConfigurationSource(configurationSource); } return(entityType?.Builder); }
private InternalEntityTypeBuilder Entity( TypeIdentity type, ConfigurationSource configurationSource, bool throwOnQuery) { if (IsIgnored(type, configurationSource)) { return(null); } var clrType = type.Type; var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType == null) { if (clrType == null) { if (Metadata.ShouldBeOwnedType(type.Name) && Metadata.HasEntityTypeWithDefiningNavigation(type.Name)) { Debug.Assert(configurationSource == ConfigurationSource.Explicit, "If a type is marked as an owned entity it can only be configured as a non-owned entity type explicitly"); Metadata.UnmarkAsOwnedType(type.Name); using (Metadata.ConventionDispatcher.StartBatch()) { foreach (var entityTypeWithDefiningNavigation in Metadata.GetEntityTypes(type.Name).ToList()) { if (entityTypeWithDefiningNavigation.GetConfigurationSource() != ConfigurationSource.Explicit) { RemoveEntityType(entityTypeWithDefiningNavigation, configurationSource); } } return(Entity(type, configurationSource, throwOnQuery)); } } Metadata.Unignore(type.Name); entityType = Metadata.AddEntityType(type.Name, configurationSource); } else { if (Metadata.ShouldBeOwnedType(clrType) && Metadata.HasEntityTypeWithDefiningNavigation(clrType)) { Debug.Assert(configurationSource == ConfigurationSource.Explicit, "If a type is marked as an owned entity it can only be configured as a non-owned entity type explicitly"); Metadata.UnmarkAsOwnedType(clrType); using (Metadata.ConventionDispatcher.StartBatch()) { foreach (var entityTypeWithDefiningNavigation in Metadata.GetEntityTypes(clrType).ToList()) { if (entityTypeWithDefiningNavigation.GetConfigurationSource() != ConfigurationSource.Explicit) { RemoveEntityType(entityTypeWithDefiningNavigation, configurationSource); } } return(Entity(type, configurationSource, throwOnQuery)); } } Metadata.Unignore(clrType); entityType = Metadata.AddEntityType(clrType, configurationSource); } } else { if (throwOnQuery && entityType.IsQueryType) { throw new InvalidOperationException( CoreStrings.CannotAccessQueryAsEntity(entityType.DisplayName())); } entityType.UpdateConfigurationSource(configurationSource); } return(entityType?.Builder); }
private InternalEntityTypeBuilder Entity( TypeIdentity type, string definingNavigationName, EntityType definingEntityType, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(null); } var clrType = type.Type; var weakEntityType = clrType == null ? Metadata.FindEntityType(type.Name, definingNavigationName, definingEntityType) : Metadata.FindEntityType(clrType, definingNavigationName, definingEntityType); if (weakEntityType == null) { var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); IConventionBatch batch = null; EntityType.Snapshot entityTypeSnapshot = null; if (entityType != null) { if (!configurationSource.Overrides(entityType.GetConfigurationSource())) { return(null); } batch = ModelBuilder.Metadata.ConventionDispatcher.StartBatch(); entityTypeSnapshot = InternalEntityTypeBuilder.DetachAllMembers(entityType); Ignore(entityType, configurationSource); } if (clrType == null) { Metadata.Unignore(type.Name); weakEntityType = Metadata.AddEntityType(type.Name, definingNavigationName, definingEntityType, configurationSource); } else { Metadata.Unignore(clrType); weakEntityType = Metadata.AddEntityType(clrType, definingNavigationName, definingEntityType, configurationSource); } if (batch != null) { entityTypeSnapshot.Attach(weakEntityType.Builder); batch.Dispose(); } } else { weakEntityType.UpdateConfigurationSource(configurationSource); } return(weakEntityType?.Builder); }
public InternalEntityTypeBuilder Entity(Type type) { var entityType = Metadata.AddEntityType(type); return(new InternalEntityTypeBuilder(entityType, new InternalModelBuilder(entityType.Model))); }
private InternalEntityTypeBuilder Entity( TypeIdentity type, ConfigurationSource configurationSource) { if (IsIgnored(type, configurationSource)) { return(null); } var clrType = type.Type; var entityType = clrType == null ? Metadata.FindEntityType(type.Name) : Metadata.FindEntityType(clrType); if (entityType == null) { if (clrType == null) { if (Metadata.ShouldBeOwnedType(type.Name)) { Debug.Assert(configurationSource == ConfigurationSource.Explicit, "If a type is marked as an owned entity it can only be configured as a non-owned entity type explicitly"); Metadata.UnmarkAsOwnedType(type.Name); using (Metadata.ConventionDispatcher.StartBatch()) { foreach (var entityTypeWithDefiningNavigation in Metadata.GetEntityTypes(type.Name).ToList()) { if (entityTypeWithDefiningNavigation.GetConfigurationSource() != ConfigurationSource.Explicit) { RemoveEntityType(entityTypeWithDefiningNavigation, configurationSource); } } } return(Entity(type, configurationSource)); } Metadata.Unignore(type.Name); entityType = Metadata.AddEntityType(type.Name, configurationSource); } else { if (Metadata.ShouldBeOwnedType(clrType)) { Debug.Assert(configurationSource == ConfigurationSource.Explicit, "If a type is marked as an owned entity it can only be configured as a non-owned entity type explicitly"); Metadata.UnmarkAsOwnedType(clrType); using (Metadata.ConventionDispatcher.StartBatch()) { foreach (var entityTypeWithDefiningNavigation in Metadata.GetEntityTypes(clrType).ToList()) { if (entityTypeWithDefiningNavigation.GetConfigurationSource() != ConfigurationSource.Explicit) { RemoveEntityType(entityTypeWithDefiningNavigation, configurationSource); } } } return(Entity(type, configurationSource)); } Metadata.Unignore(clrType); entityType = Metadata.AddEntityType(clrType, configurationSource); } } else { entityType.UpdateConfigurationSource(configurationSource); } return(entityType?.Builder); }