DapperLib / DapperLib/Dapper.Contrib
Table Attribute is being ignored
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
I've got a table and class name User, which is a keyword in SQL, so as per DapperLib/Dapper#398 I have used the table attribute as follows:
[Table("[User]")]
public class User : IUser<int>
{
public int Id { get; set; }
public string UserName { get; set; }
public bool EmailConfirmed { get; set; }
public string PasswordHash { get; set; }
public DateTime? LockoutEndDateUtc { get; set; }
public bool LockoutEnabled { get; set; }
public int AccessFailedCount { get; set; }
}
And I'm attempting to insert records like so:
public async Task CreateAsync(User user)
{
using (var connection = GetConnection())
{
await connection.InsertAsync(user);
}
}
If it matters, this is for a Dapper implementation of the backend of ASP.NET Identity.
However, I'm seeing in SQL Server Profiler that I'm writing the SQL the bare "User" instead of my specified "[User]". Upon closer inspection, it seems SqlMapperExtensions.GetTableName(Type type) is the culprit, since it early returns if the type handle's name is available.
Am I missing something here?
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 by inspecting SqlMapperExtensions.GetTableName(Type type), which the report identifies as returning the type name before honoring the [Table] attribute. Reproduce the insert with the shown User model and verify that the generated SQL uses the configured [User] table name rather than the bare type name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100