Class MappingSchema
Mapping schema.
public class MappingSchema : IConfigurationID
- Inheritance
-
MappingSchema
- Implements
- Derived
- Extension Methods
Constructors
MappingSchema()
Creates mapping schema instance.
public MappingSchema()
MappingSchema(params MappingSchema[])
Creates mapping schema, derived from other mapping schemata.
public MappingSchema(params MappingSchema[] schemas)
Parameters
schemasMappingSchema[]Base mapping schemata.
MappingSchema(string?)
Creates mapping schema for specified configuration name.
public MappingSchema(string? configuration)
Parameters
configurationstringMapping schema configuration name. ProviderName for standard names.
Remarks
Schema name should be unique for mapping schemas with different mappings. Using same name could lead to incorrect mapping used when mapping schemas with same name define different mappings for same type.
MappingSchema(string?, params MappingSchema[]?)
Creates mapping schema with specified configuration name and base mapping schemas.
public MappingSchema(string? configuration, params MappingSchema[]? schemas)
Parameters
configurationstringMapping schema configuration name. ProviderName for standard names.
schemasMappingSchema[]Base mapping schemas.
Remarks
Schema name should be unique for mapping schemas with different mappings. Using same name could lead to incorrect mapping used when mapping schemas with same name define different mappings for same type.
Fields
Default
Default mapping schema, used by LINQ to DB, when more specific mapping schema not provided.
public static MappingSchema Default
Field Value
Properties
ColumnNameComparer
Gets or sets column name comparison rules for comparison of column names in mapping with column name, returned by provider's data reader.
public StringComparer ColumnNameComparer { get; set; }
Property Value
ConfigurationList
Gets configurations, associated with current mapping schema.
public string[] ConfigurationList { get; }
Property Value
- string[]
DisplayID
public string DisplayID { get; }
Property Value
EntityDescriptorCreatedCallback
Gets or sets application-wide action, called when the EntityDescriptor is created. Could be used to adjust created descriptor before use. Not called, when connection has connection-level callback defined (OnEntityDescriptorCreated).
public static Action<MappingSchema, IEntityChangeDescriptor>? EntityDescriptorCreatedCallback { get; set; }
Property Value
IsLockable
public virtual bool IsLockable { get; }
Property Value
IsLocked
public virtual bool IsLocked { get; }
Property Value
ValueToSqlConverter
Gets value to SQL (usually literal) converter.
public ValueToSqlConverter ValueToSqlConverter { get; }
Property Value
Methods
AddMetadataReader(IMetadataReader)
Adds additional metadata attributes provider to current schema.
public void AddMetadataReader(IMetadataReader reader)
Parameters
readerIMetadataReaderMetadata attributes provider.
AddScalarType(Type, DataType, bool)
Configure provided type mapping to scalar database type.
public void AddScalarType(Type type, DataType dataType = DataType.Undefined, bool withNullable = true)
Parameters
typeTypeType to configure.
dataTypeDataTypeOptional scalar data type.
withNullableboolAlso register Nullable<T> type.
AddScalarType(Type, SqlDataType, bool)
Configure provided type mapping to scalar database type.
public void AddScalarType(Type type, SqlDataType dataType, bool withNullable = true)
Parameters
typeTypeType to configure.
dataTypeSqlDataTypeDatabase data type.
withNullableboolAlso register Nullable<T> type.
AddScalarType(Type, object?, DataType)
Configure provided type mapping to scalar database type.
public void AddScalarType(Type type, object? defaultValue, DataType dataType = DataType.Undefined)
Parameters
typeTypeType to configure.
defaultValueobjectDefault value. See SetDefaultValue(Type, object?) for more details.
dataTypeDataTypeOptional scalar data type.
AddScalarType(Type, object?, bool, DataType)
Configure provided type mapping to scalar database type.
public void AddScalarType(Type type, object? defaultValue, bool canBeNull, DataType dataType = DataType.Undefined)
Parameters
typeTypeType to configure.
defaultValueobjectDefault value. See SetDefaultValue(Type, object?) for more details.
canBeNullboolSet
nullvalue support flag. See SetCanBeNull(Type, bool) for more details.dataTypeDataTypeOptional scalar data type.
ChangeType(object?, Type)
Converts value to specified type.
public object? ChangeType(object? value, Type conversionType)
Parameters
Returns
- object
Converted value.
ChangeTypeTo<T>(object?)
Converts value to specified type.
public T ChangeTypeTo<T>(object? value)
Parameters
valueobjectValue to convert.
Returns
- T
Converted value.
Type Parameters
TTarget type.
ClearCache()
Clears EntityDescriptor cache.
public static void ClearCache()
CombineSchemas(MappingSchema, MappingSchema)
Internal API.
public static MappingSchema CombineSchemas(MappingSchema ms1, MappingSchema ms2)
Parameters
ms1MappingSchemams2MappingSchema
Returns
EnumToValue(Enum)
Converts enum value to database value.
public object? EnumToValue(Enum value)
Parameters
valueEnumEnum value.
Returns
- object
Database value.
GenerateConvertedValueExpression(object?, Type)
public Expression GenerateConvertedValueExpression(object? value, Type type)
Parameters
Returns
GenerateID()
protected virtual int GenerateID()
Returns
GenerateSafeConvert(Type, Type)
public LambdaExpression GenerateSafeConvert(Type fromType, Type type)
Parameters
Returns
GetAttribute<T>(Type)
Gets attribute of specified type, associated with specified type. Attributes are filtered by schema's configuration names (see ConfigurationList).
public T? GetAttribute<T>(Type type) where T : MappingAttribute
Parameters
typeTypeAttribute owner type.
Returns
- T
First found attribute of specified type or
null, if no attributes found.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
GetAttribute<T>(Type, MemberInfo)
Gets attribute of specified type, associated with specified type member. Attributes are filtered by schema's configuration names (see ConfigurationList).
public T? GetAttribute<T>(Type type, MemberInfo memberInfo) where T : MappingAttribute
Parameters
typeTypeMember's owner type.
memberInfoMemberInfoAttribute owner member.
Returns
- T
First found attribute of specified type or
null, if no attributes found.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
GetAttributes<T>(Type)
Gets attributes of specified type, associated with specified type. Attributes are filtered by schema's configuration names (see ConfigurationList).
public T[] GetAttributes<T>(Type type) where T : MappingAttribute
Parameters
typeTypeAttributes owner type.
Returns
- T[]
Attributes of specified type.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
GetAttributes<T>(Type, MemberInfo, bool)
Gets attributes of specified type, associated with specified type member. Attributes are filtered by schema's configuration names (see ConfigurationList).
public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool forFirstConfiguration = false) where T : MappingAttribute
Parameters
typeTypeMember's owner type.
memberInfoMemberInfoAttributes owner member.
forFirstConfigurationboolIf
true- returns only atributes for first configuration with attributes from ConfigurationList.
Returns
- T[]
Attributes of specified type.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
GetCanBeNull(Type)
Returns true, if value of specified type could contain null.
public bool GetCanBeNull(Type type)
Parameters
typeTypeValue type.
Returns
- bool
Returns
trueif specified type supportsnullvalues.
GetConvertExpression(DbDataType, DbDataType, bool, bool, ConversionType)
Returns conversion expression from from type to to type.
public LambdaExpression? GetConvertExpression(DbDataType from, DbDataType to, bool checkNull = true, bool createDefault = true, ConversionType conversionType = ConversionType.Common)
Parameters
fromDbDataTypeSource type.
toDbDataTypeTarget type.
checkNullboolIf
true, and source type could containnull, conversion expression will check converted value fornulland replace it with default value. SetDefaultValue(Type, object?) for more details.createDefaultboolCreate new conversion expression, if conversion is not defined.
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
- LambdaExpression
Conversion expression or
null, if there is no such conversion andcreateDefaultisfalse.
GetConvertExpression(Type, Type, bool, bool, ConversionType)
Returns conversion expression from from type to to type.
public LambdaExpression? GetConvertExpression(Type from, Type to, bool checkNull = true, bool createDefault = true, ConversionType conversionType = ConversionType.Common)
Parameters
fromTypeSource type.
toTypeTarget type.
checkNullboolIf
true, and source type could containnull, conversion expression will check converted value fornulland replace it with default value. SetDefaultValue(Type, object?) for more details.createDefaultboolCreate new conversion expression, if conversion is not defined.
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
- LambdaExpression
Conversion expression or
null, if there is no such conversion andcreateDefaultisfalse.
GetConvertExpression<TFrom, TTo>(bool, bool, ConversionType)
Returns conversion expression from TFrom type to TTo type.
public Expression<Func<TFrom, TTo>>? GetConvertExpression<TFrom, TTo>(bool checkNull = true, bool createDefault = true, ConversionType conversionType = ConversionType.Common)
Parameters
checkNullboolIf
true, and source type could containnull, conversion expression will check converted value fornulland replace it with default value. SetDefaultValue(Type, object?) for more details.createDefaultboolCreate new conversion expression, if conversion is not defined.
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
- Expression<Func<TFrom, TTo>>
Conversion expression or
null, if there is no such conversion andcreateDefaultisfalse.
Type Parameters
TFromSource type.
TToTarget type.
GetConverter<TFrom, TTo>(ConversionType)
Returns conversion delegate for conversion from TFrom type to TTo type.
public Func<TFrom, TTo>? GetConverter<TFrom, TTo>(ConversionType conversionType = ConversionType.Common)
Parameters
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
- Func<TFrom, TTo>
Conversion delegate or
nullif conversion is not defined.
Type Parameters
TFromSource type.
TToTarget type.
GetDataType(Type)
Returns database type mapping information for specified type.
public SqlDataType GetDataType(Type type)
Parameters
typeTypeMapped type.
Returns
- SqlDataType
Database type information.
GetDefaultFromEnumType(Type)
Returns type, to which provided enumeration type is mapped or null, if type is not configured.
See SetDefaultFromEnumType(Type, Type).
public Type? GetDefaultFromEnumType(Type enumType)
Parameters
enumTypeTypeEnumeration type.
Returns
- Type
Mapped type or
null.
GetDefaultValue(Type)
Returns default value for specified type.
Default value is a value, used instead of NULL value, read from database.
public object? GetDefaultValue(Type type)
Parameters
typeTypeValue type.
Returns
- object
Returns default value for type.
GetDefinedTypes()
Enumerates types registered by FluentMappingBuilder.
public IEnumerable<Type> GetDefinedTypes()
Returns
- IEnumerable<Type>
Returns all types, mapped by fluent mappings.
GetDynamicColumns(Type)
Gets the dynamic columns defined on given type.
public MemberInfo[] GetDynamicColumns(Type type)
Parameters
typeTypeThe type.
Returns
- MemberInfo[]
All dynamic columns defined on given type.
GetEntityDescriptor(Type, Action<MappingSchema, IEntityChangeDescriptor>?)
Returns mapped entity descriptor.
public EntityDescriptor GetEntityDescriptor(Type type, Action<MappingSchema, IEntityChangeDescriptor>? onEntityDescriptorCreated = null)
Parameters
typeTypeMapped type.
onEntityDescriptorCreatedAction<MappingSchema, IEntityChangeDescriptor>Action, called when new descriptor instance created. When set to
null, EntityDescriptorCreatedCallback callback used.
Returns
- EntityDescriptor
Mapping descriptor.
GetMapValues(Type)
Returns enum type mapping information or null for non-enum types.
public virtual MapValue[]? GetMapValues(Type type)
Parameters
typeTypeMapped type.
Returns
- MapValue[]
Mapping values for enum type and
nullfor non-enum types.
GetUnderlyingDataType(Type, out bool)
Returns scalar database type mapping information for provided type.
public SqlDataType GetUnderlyingDataType(Type type, out bool canBeNull)
Parameters
typeTypeMapped type.
canBeNullboolReturns
true, iftypetype is enum with mapping tonullvalue. Initial parameter value, passed to this method is not used.
Returns
- SqlDataType
Scalar database type information.
HasAttribute<T>(Type)
Returns true if attribute of specified type, associated with specified type.
Attributes are filtered by schema's configuration names (see ConfigurationList).
public bool HasAttribute<T>(Type type) where T : MappingAttribute
Parameters
typeTypeAttribute owner type.
Returns
- bool
Returns
trueif attribute of specified type, associated with specified type.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
HasAttribute<T>(Type, MemberInfo)
Returns true if attribute of specified type, associated with specified type member.
Attributes are filtered by schema's configuration names (see ConfigurationList).
public bool HasAttribute<T>(Type type, MemberInfo memberInfo) where T : MappingAttribute
Parameters
typeTypeMember's owner type.
memberInfoMemberInfoAttribute owner member.
Returns
- bool
Returns
trueif attribute of specified type, associated with specified type member.
Type Parameters
TMapping attribute type (must inherit MappingAttribute).
InitGenericConvertProvider(params Type[])
Initialize generic conversions for specific type parameters.
public bool InitGenericConvertProvider(params Type[] types)
Parameters
typesType[]Generic type parameters.
Returns
- bool
Returns
trueif new generic type conversions could have added to mapping schema.
InitGenericConvertProvider<T>()
Initialize generic conversions for specific type parameter.
public void InitGenericConvertProvider<T>()
Type Parameters
TGeneric type parameter, for which converters should be initialized.
IsScalarType(Type)
Returns true, if provided type mapped to scalar database type in current schema.
public bool IsScalarType(Type type)
Parameters
typeTypeType to check.
Returns
- bool
true, if type mapped to scalar database type.
SetCanBeNull(Type, bool)
Sets null value support flag for specified type.
public void SetCanBeNull(Type type, bool value)
Parameters
SetConvertExpression(DbDataType, DbDataType, LambdaExpression, bool, ConversionType)
Specify conversion expression for conversion from fromType type to toType type.
public MappingSchema SetConvertExpression(DbDataType fromType, DbDataType toType, LambdaExpression expr, bool addNullCheck = true, ConversionType conversionType = ConversionType.Common)
Parameters
fromTypeDbDataTypeSource type.
toTypeDbDataTypeTarget type.
exprLambdaExpressionConversion expression.
addNullCheckboolIf
true, conversion expression will be wrapped with default value substitution logic fornullvalues. Wrapper will be added only if source type can havenullvalues and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
SetConvertExpression(Type, Type, LambdaExpression, bool, ConversionType)
Specify conversion expression for conversion from fromType type to toType type.
public MappingSchema SetConvertExpression(Type fromType, Type toType, LambdaExpression expr, bool addNullCheck = true, ConversionType conversionType = ConversionType.Common)
Parameters
fromTypeTypeSource type.
toTypeTypeTarget type.
exprLambdaExpressionConversion expression.
addNullCheckboolIf
true, conversion expression will be wrapped with default value substitution logic fornullvalues. Wrapper will be added only if source type can havenullvalues and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
SetConvertExpression<TFrom, TTo>(Expression<Func<TFrom, TTo>>, bool, ConversionType)
Specify conversion expression for conversion from TFrom type to TTo type.
public MappingSchema SetConvertExpression<TFrom, TTo>(Expression<Func<TFrom, TTo>> expr, bool addNullCheck = true, ConversionType conversionType = ConversionType.Common)
Parameters
exprExpression<Func<TFrom, TTo>>Conversion expression.
addNullCheckboolIf
true, conversion expression will be wrapped with default value substitution logic fornullvalues. Wrapper will be added only if source type can havenullvalues and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFromSource type.
TToTarget type.
SetConvertExpression<TFrom, TTo>(Expression<Func<TFrom, TTo>>, Expression<Func<TFrom, TTo>>, ConversionType)
Specify conversion expression for conversion from TFrom type to TTo type.
public MappingSchema SetConvertExpression<TFrom, TTo>(Expression<Func<TFrom, TTo>> checkNullExpr, Expression<Func<TFrom, TTo>> expr, ConversionType conversionType = ConversionType.Common)
Parameters
checkNullExprExpression<Func<TFrom, TTo>>nullvalues conversion expression.exprExpression<Func<TFrom, TTo>>Conversion expression.
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFromSource type.
TToTarget type.
SetConverter<TFrom, TTo>(Func<TFrom, TTo>, ConversionType)
Specify conversion delegate for conversion from TFrom type to TTo type.
public MappingSchema SetConverter<TFrom, TTo>(Func<TFrom, TTo> func, ConversionType conversionType = ConversionType.Common)
Parameters
funcFunc<TFrom, TTo>Conversion delegate.
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFromSource type.
TToTarget type.
SetConverter<TFrom, TTo>(Func<TFrom, TTo>, DbDataType, DbDataType, ConversionType)
Specify conversion delegate for conversion from TFrom type to TTo type.
public MappingSchema SetConverter<TFrom, TTo>(Func<TFrom, TTo> func, DbDataType from, DbDataType to, ConversionType conversionType = ConversionType.Common)
Parameters
funcFunc<TFrom, TTo>Conversion delegate.
fromDbDataTypeSource type detalization
toDbDataTypeTarget type detalization
conversionTypeConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFromSource type.
TToTarget type.
SetCultureInfo(CultureInfo)
Set conversion expressions for conversion from and to string for basic types
(byte, sbyte, short, ushort, int, uint, long, ulong
, float, double, decimal, DateTime, DateTimeOffset)
using provided culture format providers.
public void SetCultureInfo(CultureInfo info)
Parameters
infoCultureInfoCulture with format providers for conversions.
SetDataType(Type, DataType)
Associate specified type with LINQ to DB data type.
public void SetDataType(Type type, DataType dataType)
Parameters
SetDataType(Type, SqlDataType)
Associate specified type with database data type.
public void SetDataType(Type type, SqlDataType dataType)
Parameters
typeTypeMapped type.
dataTypeSqlDataTypeDatabase data type.
SetDefaultFromEnumType(Type, Type)
Sets type, to which provided enumeration type should be mapped.
public void SetDefaultFromEnumType(Type enumType, Type defaultFromType)
Parameters
SetDefaultValue(Type, object?)
Sets default value for specific type.
Default value is a value, used instead of NULL value, read from database.
public void SetDefaultValue(Type type, object? value)
Parameters
SetGenericConvertProvider(Type)
Adds generic type conversions provider. Type converter must implement IGenericInfoProvider interface. IGenericInfoProvider for more details and examples.
public void SetGenericConvertProvider(Type type)
Parameters
typeTypeGeneric type conversions provider.
SetScalarType(Type, bool)
Configure how provided type should be handled during mapping to database - as scalar value or composite type.
public void SetScalarType(Type type, bool isScalarType = true)
Parameters
typeTypeType to configure.
isScalarTypebooltrue, if provided type should be mapped to scalar database value.
SetValueToSqlConverter(Type, Action<StringBuilder, SqlDataType, DataOptions, object>)
Sets value to SQL converter action for specific value type.
public MappingSchema SetValueToSqlConverter(Type type, Action<StringBuilder, SqlDataType, DataOptions, object> converter)
Parameters
typeTypeValue type.
converterAction<StringBuilder, SqlDataType, DataOptions, object>Converter action. Action accepts three parameters: - SQL string builder to write generated value SQL to; - value SQL type descriptor; - value.
Returns
SetValueToSqlConverter(Type, Action<StringBuilder, SqlDataType, object>)
Sets value to SQL converter action for specific value type.
public MappingSchema SetValueToSqlConverter(Type type, Action<StringBuilder, SqlDataType, object> converter)
Parameters
typeTypeValue type.
converterAction<StringBuilder, SqlDataType, object>Converter action. Action accepts three parameters: - SQL string builder to write generated value SQL to; - value SQL type descriptor; - value.
Returns
TryGetConvertExpression(Type, Type)
Returns custom value conversion expression from from type to to type if it
is defined in mapping schema, or null otherwise.
public virtual LambdaExpression? TryGetConvertExpression(Type from, Type to)
Parameters
Returns
- LambdaExpression
Conversion expression or
null, if conversion is not defined.