DapperLib / DapperLib/Dapper.Contrib
About Dapper Column Mapper Design ~ ^-^
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
hi ~
my database table design :
create table `users_orders` (
`id` int(11) unsigned not null auto_increment,
`users` int(11) not null,
`orderno` varchar(32) not null,
`normal_fee` decimal(10,2) null
)
my object class :
public class UserOrder: EntityByType
{
[Column(Name = "id")]
public int Id { get; set; }
[Column(Name = "users")]
public int UserId { get; set; }
[Column(Name = "orderno")]
public string OrderNo { get; set; }
[Column(Name = "normal_fee")]
public decimal NormalFee { get; set; }
}
my class mapper :
// TableName Mapper
SqlMapperExtensions.TableNameMapper = (type) =>
{
var tableattr = type.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic;
if (tableattr != null)
return tableattr.Name;
var name = type.Name;
if (type.IsInterface && name.StartsWith("I"))
name = name.Substring(1);
return name;
};
// Column Mapper
SqlMapper.SetTypeMap(typeof(UserOrder), new CustomPropertyTypeMap(typeof(UserOrder), (type, columnName) => type.GetProperties()
.FirstOrDefault(prop => prop.GetCustomAttributes(false).OfType<ColumnAttribute>()
.Any(attr => attr.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)))));
it can query right , but update or insert not working
my update use 'Dapper.Contrib.Extensions'
public static bool Update<T>(this IDbConnection connection, T entityToUpdate, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
error message:
Unknown column 'UserId'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Dapper.Contrib.Extensions.Update and the CustomPropertyTypeMap configuration for UserOrder; reproduce the update against the users_orders schema and compare the generated column names with the Column attributes. Done means the update and insert use the mapped database names without the Unknown column 'UserId' error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100