TypeMap
Learn on how to use the RepoDB TypeMap attribute.
This attribute maps a property to a specific database type via System.Data.DbType.
This attribute takes precedence over the type-level mapping defined in TypeMapper.
Mapping a DateTime
The following example maps a System.DateTime property to DbType.DateTime2:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
[TypeMap(DbType.DateTime2)] // Mapping this to 'DateTime2'
public DateTime DateOfBirth { get; set; }
}
Mapping a Byte Array
The following example maps a byte[] property to DbType.Binary:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
[TypeMap(DbType.Binary)] // Mapping this to 'Binary'
public byte[] Image { get; set; }
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Person>()
.DbType(e => e.DateOfBirth, DbType.DateTime2);
Retrieval
Retrieve the mapped database type via TypeMapCache:
var dbType = TypeMapCache.Get<Person>(e => e.DateOfBirth);