Only class members, mapped to columns are persisted when LinqConnect saves changes to the database. You can map fields or properties with any access level - public, private, internal, etc. LinqConnect allows you to set various parameters for mapped class members.
Parameter | Type | Description | Default Value |
---|---|---|---|
Name | String | The name of the column in the table or view. If not specified the column is assumed to have the same name as the class member. | By default, LinqConnect considers the column name equal to the property name. |
Storage | String | The name of the underlying storage. If specified it tells LinqConnect how to bypass the public property accessor for the data member and interact with the raw value itself. | If not specified LinqConnect gets and sets the value using the public accessor. |
CanBeNull | Boolean | Indicates that the value can contain the null value. This is usually inferred from the CLR type of the entity member. Use this attribute to indicate that a string value is represented as a not nullable column in the database. | True for all columns except primary key columns. |
IsPrimaryKey | Boolean | If set to true, the class member represents a column that is part of the table's primary key. If more than one member of the class is designated as the Id, the primary key is said to be a composite of the associated columns. | False |
IsDbGenerated | Boolean | Identifies that the member's column value is auto-generated by the database. IsDbGenerated members are synchronized immediately after the data row is inserted and are available after SubmitChanges() completes. | False |
IsVersion | Boolean | Identifies the member's column type as 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. Members with IsVersion=true are synchronized immediately after the data row is updated. The new values are visible after SubmitChanges() completes. | False |
IsDiscriminator | Boolean | Determines if the class member holds the discriminator value for an inheritance hierarchy. | False |
AutoSync | AutoSync | Specifies if the column is automatically synchronized from the value generated by the database on INSERT or UPDATE commands. Valid values for this tag are OnInsert, Always, and Never. | Never |
UpdateCheck | UpdateCheck |
Determines how LinqConnect implements optimistic concurrency
conflict detection. If no member is designate as IsVersion=true
detection is done by comparing original member values with current
database state. You can control which members LinqConnect uses during
conflict detection by giving each member an UpdateCheck enum
value.
|
UpdateCheck.Never |
DbType | String | Specifies the data type of the column in the database the member is mapped to. This property is used for Dynamic Database Creation. | |
Expression | String | Specifies the expression for computed properties. This property is used for Dynamic Database Creation. |
Specifying the database name is optional, and this database name will be used only if the connection itself does not specify the database name. If the database name is not specified in the context mapping and in the connection, the model database is assumed to have the same name as the context class.
Attribute Mapping
To map class members using attribute mapping, specify the Column attribute for mapped members.
C#csharp | Copy Code |
---|---|
[Table(Name="MY_TABLE")] public class MyClass { private string _ID; [Column(Storage = "_ID", IsPrimaryKey = true, AutoSync = AutoSync.OnInsert, IsDbGenerated = true, DbType = "VARCHAR2(16) NOT NULL")] public string ID { get { return _ID; } set { _ID = value; } } [Column(Name = @"CITY", CanBeNull = false, UpdateCheck = UpdateCheck.WhenChanged, DbType = "VARCHAR2(200) NOT NULL")] internal string City { get; set; } [Column] protected int TotalValue; } |
Visual Basic | Copy Code |
---|---|
<Table(Name:="MY_TABLE")> _ Public Class [MyClass] Private _ID As String <Column(Storage:="_ID", IsPrimaryKey:=True, AutoSync:=AutoSync.OnInsert, IsDbGenerated:=True, DbType:="VARCHAR2(16) NOT NULL")> _ Public Property ID As String Get Return _ID End Get Set(value As String) _ID = value End Set End Property <Column(Name:="CITY", CanBeNull:=False, UpdateCheck:=UpdateCheck.WhenChanged, DbType:="VARCHAR2(200) NOT NULL")> _ Friend Property City As String <Column()> _ Protected TotalValue As Integer End Class |
XML Mapping
Column tag is used for DataContext XML mapping. It can have attributes corresponding to the parameters from the previous table.
<?xml version="1.0" encoding="utf-8"?> <Table Name="MY_TABLE"> <Type Name="MyClass"> <Column Name="ID" Member="ID" Storage="_ID" IsPrimaryKey="true" AutoSync="OnInsert" IsDbGenerated="true" DbType="VARCHAR2(16) NOT NULL" /> <Column Name="CITY" Member="City" CanBeNull="false" UpdateCheck="WhenChanged" DbType="VARCHAR2(200) NOT NULL" /> <Column Member="TotalValue" /> </Type> </Table>
Fluent Mapping
FluentMappingBuilder class members are used. See the PropertyConfiguration Classes topic for more details.
C#csharp | Copy Code |
---|---|
FluentMappingBuilder builder = new FluentMappingBuilder(null); builder.Entity<MyClass>() .PrimaryKey(p => new { Id = p.ID }) .DbGenerated(); builder.Entity<MyClass>() .Property(p => p.ID) .Storage("_Id") .AutoSync(AutoSync.OnInsert) .ServerDataType("VARCHAR2(16) NOT NULL"); builder.Entity<MyClass>() .Property(p => p.City) .ColumnName("CITY") .NotNullable() .ConcurrencyCheck(UpdateCheck.WhenChanged) .NonUnicode() .VariableLength() .MaxLength(200); builder.Entity(typeof(MyClass)) .Property("TotalValue"); |
Visual Basic | Copy Code |
---|---|
Dim builder As New FluentMappingBuilder(Nothing) builder.Entity(Of [MyClass]) _ .PrimaryKey(Function(p) New With {.Id = p.ID}) _ .DbGenerated() builder.Entity(Of [MyClass]) _ .Property(Function(p) p.ID) _ .Storage("_Id") _ .AutoSync(AutoSync.OnInsert) _ .ServerDataType("VARCHAR2(16) NOT NULL") builder.Entity(Of [MyClass]) _ .Property(Function(p) p.City) _ .ColumnName("CITY") _ .NotNullable() _ .ConcurrencyCheck(UpdateCheck.WhenChanged) _ .NonUnicode() _ .VariableLength() _ .MaxLength(200) builder.Entity(GetType([MyClass])) _ .Property("TotalValue") |