public InvalidOperationTests() { var modelBuilder = new ModelBuilder(); IReadOnlyModel model = modelBuilder.Model; _provider = new MySqlProvider(model); }
public static IEnumerable <IReadOnlyEntityType> FindLeastDerivedEntityTypes( [NotNull] this IReadOnlyModel model, [NotNull] Type type, [CanBeNull] Func <IReadOnlyEntityType, bool>?condition = null) { var derivedLevels = new Dictionary <Type, int> { [type] = 0 }; var leastDerivedTypesGroups = model.GetEntityTypes() .GroupBy(t => GetDerivedLevel(t.ClrType, derivedLevels)) .Where(g => g.Key != int.MaxValue) .OrderBy(g => g.Key); foreach (var leastDerivedTypes in leastDerivedTypesGroups) { if (condition == null) { return(leastDerivedTypes.ToList()); } var filteredTypes = leastDerivedTypes.Where(condition).ToList(); if (filteredTypes.Count > 0) { return(filteredTypes); } } return(Enumerable.Empty <IReadOnlyEntityType>()); }
public SetupProviderConverterTests() { var modelBuilder = new ModelBuilder(); modelBuilder.Entity <Transaction>() .Property <string>("Description"); IReadOnlyModel model = modelBuilder.Model; _provider = new MySqlProvider(model); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public Sequence( string name, string?schema, IReadOnlyModel model, ConfigurationSource configurationSource) { Model = model; Name = name; _schema = schema; _configurationSource = configurationSource; _builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public static IDictionary <string, string> GetOrCreateEntityTypeErrors(this IReadOnlyModel model) { var errors = (IDictionary <string, string>?)model[ScaffoldingAnnotationNames.EntityTypeErrors]; if (errors == null) { errors = new Dictionary <string, string>(); (model as IMutableModel)?.SetEntityTypeErrors(errors); } return(errors); }
public static IReadOnlyModel Clone(this IReadOnlyModel model) { IMutableModel modelClone = new Model(); var clonedEntityTypes = new Dictionary <IReadOnlyEntityType, IMutableEntityType>(); foreach (var entityType in model.GetEntityTypes()) { var clrType = entityType.ClrType; var clonedEntityType = clrType == null ? modelClone.AddEntityType(entityType.Name) : modelClone.AddEntityType(clrType); clonedEntityTypes.Add(entityType, clonedEntityType); } foreach (var clonedEntityType in clonedEntityTypes) { if (clonedEntityType.Key.BaseType != null) { clonedEntityType.Value.BaseType = clonedEntityTypes[clonedEntityType.Key.BaseType]; } } foreach (var clonedEntityType in clonedEntityTypes) { CloneProperties(clonedEntityType.Key, clonedEntityType.Value); } foreach (var clonedEntityType in clonedEntityTypes) { CloneIndexes(clonedEntityType.Key, clonedEntityType.Value); } foreach (var clonedEntityType in clonedEntityTypes) { CloneKeys(clonedEntityType.Key, clonedEntityType.Value); } foreach (var clonedEntityType in clonedEntityTypes) { CloneForeignKeys(clonedEntityType.Key, clonedEntityType.Value); } foreach (var clonedEntityType in clonedEntityTypes) { CloneNavigations(clonedEntityType.Key, clonedEntityType.Value); } return(modelClone); }
public Sequence( [NotNull] string name, [CanBeNull] string?schema, [NotNull] IReadOnlyModel model, ConfigurationSource configurationSource) { Check.NotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); Model = model; Name = name; _schema = schema; _configurationSource = configurationSource; _builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); }
public AutoArrangingDiagram(IReadOnlyModel model) : base(model) { _incrementalLayoutEngine = new IncrementalLayoutEngine(); _layoutActionExecutor = new LayoutActionExecutorVisitor(this); _automaticLayoutCancellation = new CancellationTokenSource(); _diagramActionQueue = new Queue <DiagramAction>(); _diagramActionArrivedEvent = new AutoResetEvent(false); ShapeAdded += OnShapeAdded; ShapeRemoved += OnShapeRemoved; NodeSizeChanged += OnNodeSizeChanged; Task.Run(() => ProcessDiagramShapeActionsAsync(_automaticLayoutCancellation.Token)); }
public static IReadOnlyEntityType?FindEntityType( [NotNull] this IReadOnlyModel model, [NotNull] Type type, [NotNull] string definingNavigationName, [NotNull] IReadOnlyEntityType definingEntityType) { Check.NotNull(model, nameof(model)); Check.NotNull(type, nameof(type)); Check.NotNull(definingNavigationName, nameof(definingNavigationName)); Check.NotNull(definingEntityType, nameof(definingEntityType)); return(((Model)model).FindEntityType( type, definingNavigationName, definingEntityType.AsEntityType())); }
/// <summary> /// Returns the default identity seed. /// </summary> /// <param name="model">The model.</param> /// <returns>The default identity seed.</returns> public static long GetIdentitySeed(this IReadOnlyModel model) { if (model is RuntimeModel) { throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); } // Support pre-6.0 IdentitySeed annotations, which contained an int rather than a long var annotation = model.FindAnnotation(SqlServerAnnotationNames.IdentitySeed); return(annotation is null || annotation.Value is null ? 1 : annotation.Value is int intValue ? intValue : (long)annotation.Value); }
[Obsolete("Use the other constructor")] // DO NOT REMOVE // Used in snapsnot model processor. See issue#18557 public Sequence(IReadOnlyModel model, string annotationName) { Model = model; _configurationSource = ConfigurationSource.Explicit; var data = SequenceData.Deserialize((string)model[annotationName] !); Name = data.Name; _schema = data.Schema; _startValue = data.StartValue; _incrementBy = data.IncrementBy; _minValue = data.MinValue; _maxValue = data.MaxValue; _type = data.ClrType; _isCyclic = data.IsCyclic; _builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); }
public SqlLiteProvider(IReadOnlyModel model) : base(model) { AddConverter(new ConcatStringViaDoubleVerticalLineConverter()); AddConverter(new StringToUpperViaUpperFuncConverter()); AddConverter(new StringToLowerViaLowerFuncConverter()); AddConverter(new StringTrimViaTrimFuncConverter()); AddConverter(new StringContainsViaInstrFuncConverter()); AddConverter(new StringEndsWithViaDoubleVerticalLineConverter()); AddConverter(new StringIsNullOrEmptyConverter()); AddConverter(new MathAbsConverter()); AddConverter(new MathAcosConverter()); AddConverter(new MathAsinConverter()); AddConverter(new MathAtanConverter()); AddConverter(new MathAtan2Converter()); AddConverter(new MathCeilConverter()); AddConverter(new MathCosConverter()); AddConverter(new MathExpConverter()); AddConverter(new MathFloorConverter()); }
public SqlServerProvider(IReadOnlyModel model) : base(model) { AddConverter(new ConcatStringViaPlusConverter()); AddConverter(new StringToUpperViaUpperFuncConverter()); AddConverter(new StringToLowerViaLowerFuncConverter()); AddConverter(new StringTrimViaLtrimRtrimFuncConverter()); AddConverter(new StringContainsViaCharindexFuncConverter()); AddConverter(new StringEndsWithViaPlusConverter()); AddConverter(new StringIsNullOrEmptyConverter()); AddConverter(new MathAbsConverter()); AddConverter(new MathAcosConverter()); AddConverter(new MathAsinConverter()); AddConverter(new MathAtanConverter()); AddConverter(new MathAtn2Converter()); AddConverter(new MathCeilingConverter()); AddConverter(new MathCosConverter()); AddConverter(new MathExpConverter()); AddConverter(new MathFloorConverter()); }
public Diagram(IReadOnlyModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } Model = model; Model.EntityRenamed += OnModelEntityRenamed; Model.RelationshipAdded += OnModelRelationshipAdded; Model.EntityRemoved += OnModelEntityRemoved; Model.RelationshipRemoved += OnModelRelationshipRemoved; Model.ModelCleared += OnModelCleared; _graph = new DiagramGraph(); _graph.VertexAdded += OnDiagramNodeAddedToGraph; _graph.EdgeAdded += OnDiagramEdgeAddedToGraph; _graph.VertexRemoved += OnDiagramNodeRemovedFromGraph; _graph.EdgeRemoved += OnDiagramEdgeRemovedFromGraph; }
private void UpdateSequences(IReadOnlyModel model, string version) { if ((!version.StartsWith("1.", StringComparison.Ordinal) && !version.StartsWith("2.", StringComparison.Ordinal) && !version.StartsWith("3.", StringComparison.Ordinal)) || !(model is IMutableModel mutableModel)) { return; } var sequences = model.GetAnnotations() #pragma warning disable CS0618 // Type or member is obsolete .Where(a => a.Name.StartsWith(RelationalAnnotationNames.SequencePrefix, StringComparison.Ordinal)) .Select(a => new Sequence(model, a.Name)); #pragma warning restore CS0618 // Type or member is obsolete var sequencesDictionary = new SortedDictionary <(string, string), Sequence>(); foreach (var sequence in sequences) { sequencesDictionary[(sequence.Name, sequence.Schema)] = sequence;
public static ITriggerProvider GetSqlProvider(IReadOnlyModel model) { if (_activeProviderType is null) { throw new InvalidOperationException("To use triggers, DB provider should be added"); } var providerConstructor = _activeProviderType.GetConstructor(new[] { typeof(IReadOnlyModel) }); if (providerConstructor is null) { throw new InvalidOperationException("Provider should contain constructor with one parameter which receive instance of IModel"); } var provider = (ITriggerProvider)providerConstructor.Invoke(new[] { (object)model }); _setupProviderConverters?.Invoke(provider.Converters); return(provider); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual IModel Process(IReadOnlyModel model) { if (model == null) { return(null); } var version = model.GetProductVersion(); if (version != null) { ProcessElement(model, version); UpdateSequences(model, version); foreach (var entityType in model.GetEntityTypes()) { ProcessElement(entityType, version); ProcessCollection(entityType.GetProperties(), version); ProcessCollection(entityType.GetKeys(), version); ProcessCollection(entityType.GetIndexes(), version); foreach (var element in entityType.GetForeignKeys()) { ProcessElement(element, version); ProcessElement(element.DependentToPrincipal, version); ProcessElement(element.PrincipalToDependent, version); } } } if (model is IMutableModel mutableModel) { model = mutableModel.FinalizeModel(); } return(_modelRuntimeInitializer.Initialize((IModel)model, validationLogger: null)); }
/// <summary> /// Returns the default identity increment. /// </summary> /// <param name="model">The model.</param> /// <returns>The default identity increment.</returns> public static int GetIdentityIncrement(this IReadOnlyModel model) => (model is RuntimeModel)
/// <summary> /// Gets the default collation for all columns in the database, or <see langword="null" /> if none is defined. /// This causes EF Core to specify an explicit collation when creating all column, unless one is overridden /// on a column. /// </summary> /// <remarks> /// <p> /// See <see cref="RelationalModelExtensions.GetCollation" /> for another approach to defining a /// database-wide collation. /// </p> /// <p> /// For more information, see https://www.postgresql.org/docs/current/collation.html. /// </p> /// </remarks> public static string?GetDefaultColumnCollation(this IReadOnlyModel model) => (string?)model[NpgsqlAnnotationNames.DefaultColumnCollation];
public static IReadOnlyList <PostgresCollation> GetCollations(this IReadOnlyModel model) => PostgresCollation.GetCollations(model).ToArray();
public static string?GetTablespace(this IReadOnlyModel model) => (string?)model[NpgsqlAnnotationNames.Tablespace];
public static string?GetDatabaseTemplate(this IReadOnlyModel model) => (string?)model[NpgsqlAnnotationNames.DatabaseTemplate];
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public static IReadOnlyDictionary <string, string> GetEntityTypeErrors(this IReadOnlyModel model) => (IReadOnlyDictionary <string, string>?)model[ScaffoldingAnnotationNames.EntityTypeErrors] ?? new Dictionary <string, string>();
public static IReadOnlyList <PostgresEnum> GetPostgresEnums(this IReadOnlyModel model) => PostgresEnum.GetPostgresEnums(model).ToArray();
public static IReadOnlyList <PostgresExtension> GetPostgresExtensions(this IReadOnlyModel model) => PostgresExtension.GetPostgresExtensions(model).ToArray();
/// <summary> /// Returns the <see cref="NpgsqlValueGenerationStrategy" /> to use for properties /// of keys in the model, unless the property has a strategy explicitly set. /// </summary> /// <param name="model"> The model. </param> /// <returns> The default <see cref="NpgsqlValueGenerationStrategy" />. </returns> public static NpgsqlValueGenerationStrategy?GetValueGenerationStrategy(this IReadOnlyModel model) => (NpgsqlValueGenerationStrategy?)model[NpgsqlAnnotationNames.ValueGenerationStrategy];
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public static string?GetDatabaseName(this IReadOnlyModel model) => (string?)model[ScaffoldingAnnotationNames.DatabaseName];
/// <summary> /// Returns the name to use for the default hi-lo sequence. /// </summary> /// <param name="model">The model.</param> /// <returns>The name to use for the default hi-lo sequence.</returns> public static string GetHiLoSequenceName(this IReadOnlyModel model) => (string?)model[SqlServerAnnotationNames.HiLoSequenceName] ?? DefaultHiLoSequenceName;
/// <summary> /// Returns the schema to use for the default hi-lo sequence. /// <see cref="SqlServerPropertyBuilderExtensions.UseHiLo" /> /// </summary> /// <param name="model">The model.</param> /// <returns>The schema to use for the default hi-lo sequence.</returns> public static string?GetHiLoSequenceSchema(this IReadOnlyModel model) => (string?)model[SqlServerAnnotationNames.HiLoSequenceSchema];
public static IReadOnlyList <PostgresRange> PostgresRanges(this IReadOnlyModel model) => PostgresRange.GetPostgresRanges(model).ToArray();