Link Search Menu Expand Document

MySqlDbType


This attribute is used to set the value of the MySqlParameter.MySqlDbType property via a class property.

Works on both the MySql.Data and MySqlConnector packages.

Attribute

Below a sample code on how to use this attribute.

public class Person
{
    public int Id { get; set; }

    [MySqlDbType(MySqlDbType.Text)]
    public string Name { get; set; }
}

Fluent Mapping

Below is a sample code on how to use this attribute via FluentMapper.

FluentMapper
    .Entity<Person>()
    .PropertyValueAttributes(e => e.Name, new MySqlDbTypeAttribute(MySqlDbType.Text))

Retrieval

You can retrieve the attribute via PropertyValueAttributeCache.

var attribute = PropertyValueAttributeCache
    .Get<Person>(e => e.Name)?
    .FirstOrDefault(e => e.GetType() == typeof(MySqlDbTypeAttribute));

Or, via the PropertyValueAttributeMapper.

var attribute = PropertyValueAttributeMapper
    .Get<Person>(e => e.Name)?
    .FirstOrDefault(e => e.GetType() == typeof(MySqlDbTypeAttribute));

We strongly suggest to always use the PropertyValueAttributeCache to maximize the performance.