/// <summary> /// Sets the object that is used as the default value for the column this property is mapped to. /// </summary> /// <param name="property"> The property. </param> /// <param name="value"> The value to set. </param> public static void SetDefaultValue([NotNull] this IMutableProperty property, [CanBeNull] object value) => property.SetOrRemoveAnnotation(RelationalAnnotationNames.DefaultValue, ConvertDefaultValue(property, value));
public static Boolean IsUtc(this IMutableProperty property) => ((Boolean?)property.FindAnnotation(IsUtcAnnotation)?.Value) ?? true;
/// <summary> /// Sets the view column to which the property is mapped. /// </summary> /// <param name="property"> The property. </param> /// <param name="name"> The name to set. </param> public static void SetViewColumnName([NotNull] this IMutableProperty property, [CanBeNull] string name) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.ViewColumnName, Check.NullButNotEmpty(name, nameof(name)));
/// <summary> /// Sets a value indicating whether or not this property can persist Unicode characters. /// </summary> /// <param name="property"> The property to set the value for. </param> /// <param name="unicode"> True if the property accepts Unicode characters, false if it does not, null to clear the setting. </param> public static void IsUnicode([NotNull] this IMutableProperty property, bool?unicode) { Check.NotNull(property, nameof(property)); property[CoreAnnotationNames.UnicodeAnnotation] = unicode; }
/// <summary> /// Gets the primary key that uses this property (including a composite primary key in which this property /// is included). /// </summary> /// <param name="property"> The property to get primary key for. </param> /// <returns> /// The primary that use this property, or null if it is not part of the primary key. /// </returns> public static IMutableKey GetContainingPrimaryKey([NotNull] this IMutableProperty property) => (IMutableKey)((IProperty)property).GetContainingPrimaryKey();
/// <summary> /// Sets the Spatial Reference System Identifier (SRID) in use by the column of the property. /// </summary> /// <param name="property">The property to set the columns SRID for.</param> /// <param name="srid">The SRID to configure for the property's column.</param> public static void SetSpatialReferenceSystem([NotNull] this IMutableProperty property, int?srid) => property.SetOrRemoveAnnotation(MySqlAnnotationNames.SpatialReferenceSystemId, srid);
/// <summary> /// Sets the type that the property value will be converted to before being sent to the database provider. /// </summary> /// <param name="property"> The property. </param> /// <param name="providerClrType"> The type to use, or <c>null</c> to remove any previously set type. </param> public static void SetProviderClrType([NotNull] this IMutableProperty property, [CanBeNull] Type providerClrType) => property[CoreAnnotationNames.ProviderClrType] = providerClrType;
/// <summary> /// Sets the type that the property value will be converted to before being sent to the database provider. /// </summary> /// <param name="property"> The property. </param> /// <param name="providerClrType"> The type to use, or <c>null</c> to remove any previously set type. </param> public static void SetProviderClrType([NotNull] this IMutableProperty property, [CanBeNull] Type providerClrType) => property.AsProperty().SetProviderClrType(providerClrType, ConfigurationSource.Explicit);
/// <summary> /// Sets the custom <see cref="ValueComparer" /> for structural copies for this property. /// </summary> /// <param name="property"> The property. </param> /// <param name="comparer"> The comparer, or <c>null</c> to remove any previously set comparer. </param> public static void SetStructuralValueComparer([NotNull] this IMutableProperty property, [CanBeNull] ValueComparer comparer) => property.AsProperty().SetStructuralValueComparer(comparer, ConfigurationSource.Explicit);
/// <summary> /// <para> /// Gets or sets a value indicating whether this property can be modified after the entity is /// saved to the database. /// </para> /// <para> /// If <see cref="PropertySaveBehavior.Throw" />, then an exception /// will be thrown if a new value is assigned to this property after the entity exists in the database. /// </para> /// <para> /// If <see cref="PropertySaveBehavior.Ignore" />, then any modification to the /// property value of an entity that already exists in the database will be ignored. /// </para> /// </summary> /// <param name="property"> The property. </param> /// <param name="afterSaveBehavior"> /// A value indicating whether this property can be modified after the entity is saved to the database. /// </param> public static void SetAfterSaveBehavior([NotNull] this IMutableProperty property, PropertySaveBehavior?afterSaveBehavior) => property.AsProperty().SetAfterSaveBehavior(afterSaveBehavior, ConfigurationSource.Explicit);
/// <summary> /// <para> /// Sets the factory to use for generating values for this property, or <c>null</c> to clear any previously set factory. /// </para> /// <para> /// Setting <c>null</c> does not disable value generation for this property, it just clears any generator explicitly /// configured for this property. The database provider may still have a value generator for the property type. /// </para> /// </summary> /// <param name="property"> The property to set the value generator for. </param> /// <param name="valueGeneratorFactory"> /// A factory that will be used to create the value generator, or <c>null</c> to /// clear any previously set factory. /// </param> public static void SetValueGeneratorFactory( [NotNull] this IMutableProperty property, [NotNull] Func <IProperty, IEntityType, ValueGenerator> valueGeneratorFactory) => property.AsProperty().SetValueGeneratorFactory(valueGeneratorFactory, ConfigurationSource.Explicit);
/// <summary> /// Sets the schema to use for the hi-lo sequence. /// </summary> /// <param name="property">The property.</param> /// <param name="schema">The schema to use.</param> public static void SetHiLoSequenceSchema([NotNull] this IMutableProperty property, [CanBeNull] string schema) => property.SetOrRemoveAnnotation( NpgsqlAnnotationNames.HiLoSequenceSchema, Check.NullButNotEmpty(schema, nameof(schema)));
/// <summary> /// Sets the name to use for the hi-lo sequence. /// </summary> /// <param name="property">The property.</param> /// <param name="name">The sequence name to use.</param> public static void SetHiLoSequenceName([NotNull] this IMutableProperty property, [CanBeNull] string name) => property.SetOrRemoveAnnotation( NpgsqlAnnotationNames.HiLoSequenceName, Check.NullButNotEmpty(name, nameof(name)));
/// <summary> /// Removes all identity sequence annotations from the property. /// </summary> public static void RemoveHiLoOptions([NotNull] this IMutableProperty property) { property.SetHiLoSequenceName(null); property.SetHiLoSequenceSchema(null); }
private void MapColumnNames(IMutableProperty property) { var columnName = property.Relational().ColumnName; property.Relational().ColumnName = _nameTranslator.TranslateMemberName(columnName); }
/// <summary> /// Finds the principal property by the given property is constrained assuming that /// the given property is part of a foreign key. /// </summary> /// <param name="property"> The foreign key property. </param> /// <returns> The associated principal property, or <c>null</c> if none exists. </returns> public static IMutableProperty FindPrincipal([NotNull] this IMutableProperty property) => (IMutableProperty)((IProperty)property).FindPrincipal();
/// <summary> /// Sets the name of the collation in use by the column of the property. /// </summary> /// <param name="property">The property to set the columns collation for.</param> /// <param name="collation">The name of the collation used for the column of the property.</param> public static void SetCollation([NotNull] this IMutableProperty property, string collation) => property.SetOrRemoveAnnotation(MySqlAnnotationNames.Collation, collation);
public static IMutableKey GetContainingPrimaryKey([NotNull] this IMutableProperty property) => property.FindContainingPrimaryKey();
/// <summary> /// Gets the Oracle specific metadata for a property. /// </summary> /// <param name="property"> The property to get metadata for. </param> /// <returns> The Oracle specific metadata for the property. </returns> public static OraclePropertyAnnotations Oracle([NotNull] this IMutableProperty property) => (OraclePropertyAnnotations)Oracle((IProperty)property);
/// <summary> /// Sets the maximum length of data that is allowed in this property. For example, if the property is a <see cref="string" /> ' /// then this is the maximum number of characters. /// </summary> /// <param name="property"> The property to set the maximum length of. </param> /// <param name="maxLength"> The maximum length of data that is allowed in this property. </param> public static void SetMaxLength([NotNull] this IMutableProperty property, int?maxLength) => property.AsProperty().SetMaxLength(maxLength, ConfigurationSource.Explicit);
/// <summary> /// Sets the custom <see cref="ValueComparer" /> for deep copies for this property. /// </summary> /// <param name="property"> The property. </param> /// <param name="comparer"> The comparer, or <c>null</c> to remove any previously set comparer. </param> public static void SetDeepValueComparer([NotNull] this IMutableProperty property, [CanBeNull] ValueComparer comparer) { CheckComparerType(property, comparer); property[CoreAnnotationNames.DeepValueComparer] = comparer; }
/// <summary> /// Sets a value indicating whether this property can persist Unicode characters. /// </summary> /// <param name="property"> The property to set the value for. </param> /// <param name="unicode"> /// <c>true</c> if the property accepts Unicode characters, <c>false</c> if it does not, <c>null</c> to clear the setting. /// </param> public static void SetIsUnicode([NotNull] this IMutableProperty property, bool?unicode) => property.AsProperty().SetIsUnicode(unicode, ConfigurationSource.Explicit);
/// <summary> /// Gets all foreign keys that use this property (including composite foreign keys in which this property /// is included). /// </summary> /// <param name="property"> The property to get foreign keys for. </param> /// <returns> /// The foreign keys that use this property. /// </returns> public static IEnumerable <IMutableForeignKey> GetContainingForeignKeys([NotNull] this IMutableProperty property) => ((IProperty)property).GetContainingForeignKeys().Cast <IMutableForeignKey>();
private static void GenerateMapping(IMutableProperty property) => property[CoreAnnotationNames.TypeMapping] = new TestRelationalTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(property);
/// <summary> /// Adds an index to this entity type. /// </summary> /// <param name="entityType"> The entity type. </param> /// <param name="property"> The property to be indexed. </param> /// <returns> The newly created index. </returns> public static IMutableIndex AddIndex( [NotNull] this IMutableEntityType entityType, [NotNull] IMutableProperty property) => Check.NotNull(entityType, nameof(entityType)).AddIndex(new[] { property });
/// <summary> /// Gets the SQL Server Compact specific metadata for a property. /// </summary> /// <param name="property"> The property to get metadata for. </param> /// <returns> The SQL Server Compact specific metadata for the property. </returns> public static RelationalPropertyAnnotations SqlCe([NotNull] this IMutableProperty property) => (RelationalPropertyAnnotations)SqlCe((IProperty)property);
private static void GenerateMapping(IMutableProperty property) => property[CoreAnnotationNames.TypeMapping] = new TestRelationalTypeMappingSource( TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(), TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>()) .FindMapping(property);
/// <summary> /// Sets specific change tracking options for this JSON property, that specify how inner properties or array /// elements will be tracked. Applies to simple strings, POCOs and DOM objects. Using `null` restores all /// defaults. /// </summary> /// <param name="property">The JSON property to set the change tracking options for.</param> /// <param name="options">The change tracking option to configure for the JSON property.</param> public static void SetJsonChangeTrackingOptions([NotNull] this IMutableProperty property, MySqlCommonJsonChangeTrackingOptions?options) => property.SetJsonChangeTrackingOptions(options?.ToJsonChangeTrackingOptions());
/// <summary> /// Sets the SQL expression that is used as the computed value for the column this property is mapped to. /// </summary> /// <param name="property"> The property. </param> /// <param name="value"> The value to set. </param> public static void SetComputedColumnSql([NotNull] this IMutableProperty property, [CanBeNull] string value) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.ComputedColumnSql, Check.NullButNotEmpty(value, nameof(value)));
/// <summary> /// Sets the name of the charset in use by the column of the property. /// </summary> /// <param name="property">The property to set the columns charset for.</param> /// <param name="charSet">The name of the charset used for the column of the property.</param> public static void SetCharSet([NotNull] this IMutableProperty property, string charSet) => property.SetOrRemoveAnnotation(MySqlAnnotationNames.CharSet, charSet);
protected virtual void ConfigureProperty(IMutableProperty property, string configuration, string value) { var propertyAnnotations = property.Relational(); switch (configuration) { case nameof(RelationalPropertyAnnotations.DefaultValue): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.DefaultValue = value; break; case nameof(RelationalPropertyAnnotations.DefaultValueSql): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.DefaultValueSql = value; break; case nameof(RelationalPropertyAnnotations.ComputedColumnSql): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.ComputedColumnSql = value; break; default: throw new NotImplementedException(); } }
protected virtual void ConfigureProperty(IMutableProperty property, string configuration, string value) { var propertyAnnotations = property.SqlServer(); switch (configuration) { case nameof(RelationalPropertyAnnotations.DefaultValue): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.DefaultValue = int.Parse(value); break; case nameof(RelationalPropertyAnnotations.DefaultValueSql): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.DefaultValueSql = value; break; case nameof(RelationalPropertyAnnotations.ComputedColumnSql): property.ValueGenerated = ValueGenerated.OnAddOrUpdate; propertyAnnotations.ComputedColumnSql = value; break; case nameof(SqlServerPropertyAnnotations.ValueGenerationStrategy): property.ValueGenerated = ValueGenerated.OnAdd; propertyAnnotations.ValueGenerationStrategy = SqlServerValueGenerationStrategy.IdentityColumn; break; default: throw new NotImplementedException(); } }