Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Dapper to enforce 'required' properties are present #145

Open
Dreamescaper opened this issue Feb 7, 2025 · 1 comment
Open

Allow Dapper to enforce 'required' properties are present #145

Dreamescaper opened this issue Feb 7, 2025 · 1 comment

Comments

@Dreamescaper
Copy link

I would be nice to be able to configure Dapper to respect 'required' annotations:

public class DataResult
{
    public required string StringValue { get; set; }
    public required int IntValue { get; set; }
}

...

await connectionQueryAsync<DataResult>("[proc_MyStoredProc]");
// Should throw an exception if `StringValue` or `IntValue` are not provided

Suggested API changes:

SqlMapper.Settings.RespectRequiredModifiers = true;
@mgravell
Copy link
Member

mgravell commented Feb 7, 2025

I doubt we would add this to vanilla Dapper, due to ever-increasing complexity - but: Dapper.AOT already detects required to ensure that the values get assigned appropriately; we could, perhaps, consider adding an attribute such as [EnforceRequired([true])] that enables this.

@mgravell mgravell transferred this issue from DapperLib/Dapper Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants