public bool UnmapComposite(Type clrType, string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) { if (pgName != null && string.IsNullOrWhiteSpace(pgName)) { throw new ArgumentException("pgName can't be empty.", nameof(pgName)); } nameTranslator ??= DefaultNameTranslator; pgName ??= GetPgName(clrType, nameTranslator); return(RemoveMapping(pgName)); }
/// <summary> /// Registers a user-defined enum type in the model. /// </summary> /// <param name="modelBuilder">The model builder in which to create the enum type.</param> /// <param name="schema">The schema in which to create the enum type.</param> /// <param name="name">The name of the enum type to create.</param> /// <param name="nameTranslator"> /// The translator for name and label inference. /// Defaults to <see cref="NpgsqlSnakeCaseNameTranslator"/>.</param> /// <typeparam name="TEnum"></typeparam> /// <returns> /// The updated <see cref="ModelBuilder"/>. /// </returns> /// <remarks> /// See: https://www.postgresql.org/docs/current/static/datatype-enum.html /// </remarks> /// <exception cref="ArgumentNullException">builder</exception> public static ModelBuilder HasPostgresEnum <TEnum>( this ModelBuilder modelBuilder, string?schema = null, string?name = null, INpgsqlNameTranslator?nameTranslator = null) where TEnum : struct, Enum { if (nameTranslator is null) { nameTranslator = NpgsqlConnection.GlobalTypeMapper.DefaultNameTranslator; } return(modelBuilder.HasPostgresEnum( schema, name ?? GetTypePgName <TEnum>(nameTranslator), GetMemberPgNames <TEnum>(nameTranslator))); }
public bool UnmapComposite <T>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) { if (pgName != null && pgName.Trim() == "") { throw new ArgumentException("pgName can't be empty", nameof(pgName)); } if (nameTranslator == null) { nameTranslator = DefaultNameTranslator; } if (pgName == null) { pgName = GetPgName <T>(nameTranslator); } return(RemoveMapping(pgName)); }
public bool UnmapEnum <TEnum>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) where TEnum : struct, Enum { if (pgName != null && pgName.Trim() == "") { throw new ArgumentException("pgName can't be empty", nameof(pgName)); } if (nameTranslator == null) { nameTranslator = DefaultNameTranslator; } if (pgName == null) { pgName = GetPgName(typeof(TEnum), nameTranslator); } return(RemoveMapping(pgName)); }
public NpgsqlEnumTypeMapping( string storeType, string?storeTypeSchema, Type enumType, ISqlGenerationHelper sqlGenerationHelper, INpgsqlNameTranslator?nameTranslator = null) : base(sqlGenerationHelper.DelimitIdentifier(storeType, storeTypeSchema), enumType) { if (!enumType.IsEnum || !enumType.IsValueType) { throw new ArgumentException($"Enum type mappings require a CLR enum. {enumType.FullName} is not an enum."); } nameTranslator ??= NpgsqlConnection.GlobalTypeMapper.DefaultNameTranslator; _nameTranslator = nameTranslator; _sqlGenerationHelper = sqlGenerationHelper; _members = CreateValueMapping(enumType, nameTranslator); }
INpgsqlTypeMapper MapComposite(string?pgName, INpgsqlNameTranslator?nameTranslator, Type type, Func <INpgsqlNameTranslator, NpgsqlTypeHandlerFactory> factory) { if (pgName != null && string.IsNullOrWhiteSpace(pgName)) { throw new ArgumentException("pgName can't be empty.", nameof(pgName)); } nameTranslator ??= DefaultNameTranslator; pgName ??= GetPgName(type, nameTranslator); return(AddMapping( new NpgsqlTypeMappingBuilder { PgTypeName = pgName, ClrTypes = new[] { type }, TypeHandlerFactory = factory(nameTranslator), } .Build())); }
public INpgsqlTypeMapper MapComposite <T>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) { if (pgName != null && pgName.Trim() == "") { throw new ArgumentException("pgName can't be empty", nameof(pgName)); } if (nameTranslator == null) { nameTranslator = DefaultNameTranslator; } if (pgName == null) { pgName = GetPgName <T>(nameTranslator); } return(AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = pgName, ClrTypes = new[] { typeof(T) }, TypeHandlerFactory = new MappedCompositeTypeHandlerFactory <T>(nameTranslator) }.Build())); }
public INpgsqlTypeMapper MapEnum <TEnum>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) where TEnum : struct, Enum { if (pgName != null && pgName.Trim() == "") { throw new ArgumentException("pgName can't be empty", nameof(pgName)); } if (nameTranslator == null) { nameTranslator = DefaultNameTranslator; } if (pgName == null) { pgName = GetPgName(typeof(TEnum), nameTranslator); } return(AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = pgName, ClrTypes = new[] { typeof(TEnum) }, TypeHandlerFactory = new EnumTypeHandlerFactory <TEnum>(nameTranslator) }.Build())); }
/// <inheritdoc /> public abstract bool UnmapComposite(Type clrType, string?pgName = null, INpgsqlNameTranslator?nameTranslator = null);
/// <inheritdoc /> public abstract bool UnmapComposite <T>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null);
public abstract INpgsqlTypeMapper MapComposite(Type clrType, string?pgName = null, INpgsqlNameTranslator?nameTranslator = null);
/// <inheritdoc /> public abstract bool UnmapEnum <TEnum>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) where TEnum : struct, Enum;
/// <inheritdoc /> public abstract INpgsqlTypeMapper MapEnum <TEnum>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) where TEnum : struct, Enum;
public INpgsqlTypeMapper MapComposite(Type clrType, string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) => MapComposite(pgName, nameTranslator, clrType, t => (NpgsqlTypeHandlerFactory) Activator.CreateInstance(typeof(CompositeTypeHandlerFactory <>).MakeGenericType(clrType), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { t }, null) !);
public INpgsqlTypeMapper MapComposite <T>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) => MapComposite(pgName, nameTranslator, typeof(T), t => new CompositeTypeHandlerFactory <T>(t));
public INpgsqlTypeMapper MapComposite(Type clrType, string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) => MapComposite(pgName, nameTranslator, clrType, t => (NpgsqlTypeHandlerFactory) Activator.CreateInstance(typeof(CompositeTypeHandlerFactory <>).MakeGenericType(clrType), t) !);
public bool UnmapComposite <T>(string?pgName = null, INpgsqlNameTranslator?nameTranslator = null) => UnmapComposite(typeof(T), pgName, nameTranslator);