LinqConnect Documentation
In This Topic
    PropertyConfiguration Classes
    In This Topic
    PropertyConfiguration Classes
    LinqConnect Documentation
    PropertyConfiguration Classes
    [email protected]

    This classes are intended to define mapping for properties. The PropertyConfiguration class is the base class for all property configuration. Its descendants have the specific methods for properties of specific types.

    PropertyConfiguration Class

    The PropertyConfiguration class has the following descendants:

    The PropertyConfiguration class has the following methods:

    • ColumnName(string name) - specifies the column name. You may specify quoted or unquoted column name. If the column name is not quoted, and the database requires this name to be quoted, the provider will quote it when generating SQL. If column name is not specified, the PropertyNameConvention default convention will generate it and quote it if necessary according to the database syntax.
    • ColumnOrder(int ordinal) - specifies the number of the column in the table. Affects the CreateDatabase behaviour when generating the CREATE TABLE statement. If ColumnOrder is not set, the PropertyOrderConvention default convention will set it.
    • ServerDataType(string serverDataTypeName) - specifies the database-specific data type. If it is not set, ServerDataTypeConvention will generate the correct database-specific type. See the Data Type Generation chapter below for more information.
    • DefaultValue(string defaultValue) - specifies the default value.
    • ConcurrencyCheck(UpdateCheck updateCheck) - specifies whether to consider this column when performing concurrency check (UpdateCheck).
    • DbGenerated() - specifies that the value of this column is generated by the database.
    • AutoSync(AutoSync autoSync) - specifies the column AutoSync mode.
    • Storage(string memberName) and Storage(MemberInfo member) - specifies the non-public property or field to store value. Usually is used for public ReadOnly properties or public properties, that have some additional logic for IPropertyChanging/IPropertyChanged and it is preferable to work with non-public fields.

    SizablePropertyConfiguration Class

    SizablePropertyConfiguration is an abstract parent class for StringPropertyConfiguration and BinaryPropertyConfiguration classes, that is used for defining mapping configuration for string and binary properties. The SizablePropertyConfiguration has the following public methods:

    • MaxLength(int maxLength) - specifies the column maximal length.
    • FixedLength() - specifies that this column contains fixed length data.
    • VariableLength() - specifies that this column contains variable length data. If neither FixedLength() nor VariableLength() were explicitly called for a property, the StringPropertyConvention convention sets VariableLength() for string columns, and BinaryPropertyConvention does the same for Byte[] or LinqBinary columns.
    • Nullable() and NotNullable() - specify whether the column is nullable. The StringPropertyConvention convention sets Nullable() for string columns by default if Nullable() or NotNullable() were not executed explicitly for this property. BinaryPropertyConvention does the same for Byte[] or LinqBinary columns.

    StringPropertyConfiguration Class

    The StringPropertyConfiguration class is used for defining mapping configuration for string properties. Its public methods are listed below:

    • Unicode() - specifies the column contains Unicode character data.
    • NonUnicode() - specifies that this column contains non-Unicode character data.

    The StringPropertyConvention convention sets Unicode() for String columns by default if neither Unicode() nor NonUnicode() were executed explicitly for this property.

    BinaryPropertyConfiguration Class

    The BinaryPropertyConfiguration class is used for defining mapping configuration for Byte[] or LinqBinary properties. Its public methods are listed below:

    • IsRowVersion() - specifies that the column is a database timestamp or a version number. Version numbers are incremented and timestamp columns are updated by the database every time the associated row is updated.

    NumericPropertyConfiguration Class

    The NumericPropertyConfiguration class is used for defining mapping configuration for properties of type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64. It is the base class for DecimalPropertyConfiguration. Its public methods are listed below:

    • Precision(int precision) - specifies the column precision.

    DecimalPropertyConfiguration Class

    The DecimalPropertyConfiguration class is used for defining mapping configuration for properties of type Decimal, Single, or Double. Its public methods are listed below:

    • Scale(int scale) - specifies the column scale.

    DateTimePropertyConfiguration Class

    The DateTimePropertyConfiguration class is used for defining mapping configuration for DateTime properties. Its public methods are listed below:

    • Precision(int precision) - specifies precision of the DateTime type for the storage of fractional values for seconds.

    Data Type Generation

    Nullable/NotNullable, MaxLength, FixedLength/VariableLength, Unicode/NonUnicode, Precision and Scale values are used by the ServerDataTypeConvention convention for defining ServerDataType if it is not defined. If ServerDataType is specified explicitly, there is no need to specify Nullable/NotNullable, MaxLength, FixedLength/VariableLength, Unicode/NonUnicode, Precision and Scale values.

    However, still it is better to set Nullable/NotNullable explicitly for building LinqConnect metadata correctly, even though Nullable/NotNullable can be set by default conventions.

    There is a point to set Unicode/NonUnicode parameters only in databases that treat Unicode and non-Unicode strings differently, for example, in Oracle.

    Note:
    When setting the precision for DateTime properties, you should take into account that some databases cannot store DateTime values with high precision. System.DateTime allows storing time values with 7 places after the decimal point; its accuracy is 100 nanoseconds. Oracle and SQLite can store values with such precision. MySQL does not have a data type to store fractional seconds. PostgreSQL TIMESTAMP data type theoretically can can store fractional seconds up to microseconds (6 places after the decimal point), however the precision may vary, and microsecond precision is not guaranteed.

    Example:

    builder.ComplexType<AddressType>()
        .Property(p => p.Country)
            .ColumnName(@"COUNTRY")
            .NotNullable()
            .MaxLength(100)
            .NonUnicode()
            .VariableLength();
     
    builder.ComplexType<AddressType>()
        .Property(p => p.City)
            .ColumnName(@"CITY")
            .NotNullable()
            .ServerDataType(@"VARCHAR2(100) NOT NULL");