querybuilder
querybuilder copied to clipboard
Attribute map not working
By refering to
https://github.com/sqlkata/querybuilder/issues/261 and https://github.com/sqlkata/querybuilder/issues/212 I tried to implement the attribute map in my model
using SqlKata;
namespace PrismDemo.Models
{
public class User
{
[Ignore]
[Column("user_id")]
public int Id { get; set; }
[Column("username")]
public string Name { get; set; }
[Column("password")]
public string Pass { get; set; }
[Column("user_first_name")]
public string FirstName { get; set; }
[Column("user_last_name")]
public string LastName { get; set; }
[Column("user_gender")]
public int Genders { get; set; }
public User()
{
}
}
}
but it look like doesn't work, below is the break point captured
I did put in this code: Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
After several tried, found it only work, if attribute and field name are same, example user_first_name to UserFirstName
Please help advice did I made a mistake which cause it not working?
Thank you
I just discovered the same issue.
One option is set a custom mapper.
public static PropertyInfo CustomPropertyMapper(Type type, string columnName) { //find and return the property with property name or column name }
SqlMapper.TypeMapProvider = (Type type) => new CustomPropertyTypeMap(type, CustomPropertyMapper);
It's not working because SqlKata attributes eg. "Column" are used only for SqlKata.Execution Insert/Update. For now you have to use additional standard-dapper mapping methods.