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
schemas
MappingSchema[]Base mapping schemata.
MappingSchema(string?)
Creates mapping schema for specified configuration name.
public MappingSchema(string? configuration)
Parameters
configuration
stringMapping 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
configuration
stringMapping schema configuration name. ProviderName for standard names.
schemas
MappingSchema[]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
reader
IMetadataReaderMetadata 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
type
TypeType to configure.
dataType
DataTypeOptional scalar data type.
withNullable
boolAlso 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
type
TypeType to configure.
dataType
SqlDataTypeDatabase data type.
withNullable
boolAlso 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
type
TypeType to configure.
defaultValue
objectDefault value. See SetDefaultValue(Type, object?) for more details.
dataType
DataTypeOptional 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
type
TypeType to configure.
defaultValue
objectDefault value. See SetDefaultValue(Type, object?) for more details.
canBeNull
boolSet
null
value support flag. See SetCanBeNull(Type, bool) for more details.dataType
DataTypeOptional 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
value
objectValue to convert.
Returns
- T
Converted value.
Type Parameters
T
Target type.
ClearCache()
Clears EntityDescriptor cache.
public static void ClearCache()
CombineSchemas(MappingSchema, MappingSchema)
Internal API.
public static MappingSchema CombineSchemas(MappingSchema ms1, MappingSchema ms2)
Parameters
ms1
MappingSchemams2
MappingSchema
Returns
EnumToValue(Enum)
Converts enum value to database value.
public object? EnumToValue(Enum value)
Parameters
value
EnumEnum 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
type
TypeAttribute owner type.
Returns
- T
First found attribute of specified type or
null
, if no attributes found.
Type Parameters
T
Mapping 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
type
TypeMember's owner type.
memberInfo
MemberInfoAttribute owner member.
Returns
- T
First found attribute of specified type or
null
, if no attributes found.
Type Parameters
T
Mapping 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
type
TypeAttributes owner type.
Returns
- T[]
Attributes of specified type.
Type Parameters
T
Mapping 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
type
TypeMember's owner type.
memberInfo
MemberInfoAttributes owner member.
forFirstConfiguration
boolIf
true
- returns only atributes for first configuration with attributes from ConfigurationList.
Returns
- T[]
Attributes of specified type.
Type Parameters
T
Mapping attribute type (must inherit MappingAttribute).
GetCanBeNull(Type)
Returns true
, if value of specified type could contain null
.
public bool GetCanBeNull(Type type)
Parameters
type
TypeValue type.
Returns
- bool
Returns
true
if specified type supportsnull
values.
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
from
DbDataTypeSource type.
to
DbDataTypeTarget type.
checkNull
boolIf
true
, and source type could containnull
, conversion expression will check converted value fornull
and replace it with default value. SetDefaultValue(Type, object?) for more details.createDefault
boolCreate new conversion expression, if conversion is not defined.
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
- LambdaExpression
Conversion expression or
null
, if there is no such conversion andcreateDefault
isfalse
.
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
from
TypeSource type.
to
TypeTarget type.
checkNull
boolIf
true
, and source type could containnull
, conversion expression will check converted value fornull
and replace it with default value. SetDefaultValue(Type, object?) for more details.createDefault
boolCreate new conversion expression, if conversion is not defined.
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
- LambdaExpression
Conversion expression or
null
, if there is no such conversion andcreateDefault
isfalse
.
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
checkNull
boolIf
true
, and source type could containnull
, conversion expression will check converted value fornull
and replace it with default value. SetDefaultValue(Type, object?) for more details.createDefault
boolCreate new conversion expression, if conversion is not defined.
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
- Expression<Func<TFrom, TTo>>
Conversion expression or
null
, if there is no such conversion andcreateDefault
isfalse
.
Type Parameters
TFrom
Source type.
TTo
Target 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
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
- Func<TFrom, TTo>
Conversion delegate or
null
if conversion is not defined.
Type Parameters
TFrom
Source type.
TTo
Target type.
GetDataType(Type)
Returns database type mapping information for specified type.
public SqlDataType GetDataType(Type type)
Parameters
type
TypeMapped 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
enumType
TypeEnumeration 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
type
TypeValue 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
type
TypeThe 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
type
TypeMapped type.
onEntityDescriptorCreated
Action<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
type
TypeMapped type.
Returns
- MapValue[]
Mapping values for enum type and
null
for 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
type
TypeMapped type.
canBeNull
boolReturns
true
, iftype
type is enum with mapping tonull
value. 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
type
TypeAttribute owner type.
Returns
- bool
Returns
true
if attribute of specified type, associated with specified type.
Type Parameters
T
Mapping 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
type
TypeMember's owner type.
memberInfo
MemberInfoAttribute owner member.
Returns
- bool
Returns
true
if attribute of specified type, associated with specified type member.
Type Parameters
T
Mapping attribute type (must inherit MappingAttribute).
InitGenericConvertProvider(params Type[])
Initialize generic conversions for specific type parameters.
public bool InitGenericConvertProvider(params Type[] types)
Parameters
types
Type[]Generic type parameters.
Returns
- bool
Returns
true
if 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
T
Generic 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
type
TypeType 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
fromType
DbDataTypeSource type.
toType
DbDataTypeTarget type.
expr
LambdaExpressionConversion expression.
addNullCheck
boolIf
true
, conversion expression will be wrapped with default value substitution logic fornull
values. Wrapper will be added only if source type can havenull
values and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionType
ConversionTypeConversion 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
fromType
TypeSource type.
toType
TypeTarget type.
expr
LambdaExpressionConversion expression.
addNullCheck
boolIf
true
, conversion expression will be wrapped with default value substitution logic fornull
values. Wrapper will be added only if source type can havenull
values and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionType
ConversionTypeConversion 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
expr
Expression<Func<TFrom, TTo>>Conversion expression.
addNullCheck
boolIf
true
, conversion expression will be wrapped with default value substitution logic fornull
values. Wrapper will be added only if source type can havenull
values and conversion expression doesn't use default value provider. See DefaultValue<T> and DefaultValue types for more details.conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFrom
Source type.
TTo
Target 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
checkNullExpr
Expression<Func<TFrom, TTo>>null
values conversion expression.expr
Expression<Func<TFrom, TTo>>Conversion expression.
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFrom
Source type.
TTo
Target 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
func
Func<TFrom, TTo>Conversion delegate.
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFrom
Source type.
TTo
Target 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
func
Func<TFrom, TTo>Conversion delegate.
from
DbDataTypeSource type detalization
to
DbDataTypeTarget type detalization
conversionType
ConversionTypeConversion type. See ConversionType for more details.
Returns
Type Parameters
TFrom
Source type.
TTo
Target 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
info
CultureInfoCulture 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
type
TypeMapped type.
dataType
SqlDataTypeDatabase 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
type
TypeGeneric 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
type
TypeType to configure.
isScalarType
booltrue
, 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
type
TypeValue type.
converter
Action<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
type
TypeValue type.
converter
Action<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.