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

DbString - analyzer and runtime #89

Open
mgravell opened this issue Nov 21, 2023 · 2 comments · May be fixed by #119
Open

DbString - analyzer and runtime #89

mgravell opened this issue Nov 21, 2023 · 2 comments · May be fixed by #119
Assignees
Labels
analyzer enhancement New feature or request

Comments

@mgravell
Copy link
Member

mgravell commented Nov 21, 2023

DbString is a Dapper type that allows metadata to be conveyed for string types.

However:

  • it is allocatey
  • it isn't touched by AOT today
  • what it achieves is the same as DbValue]

Suggestions:

  1. we need to verify that [DbValue] allows the size and type to be conveyed into DbParameter
  2. we should emit a warning to use [DbValue] instead
  3. we should probably treat DbString as a recognized type, and configure things correctly
  4. for this last, I would propose (if any DbString are encountered) writing a helper method into the output (we have some prior art that copies entire files into the output; that would be fine) with a method that takes a DbParameter and DbString (global:: qualified) and does the right things:
  • if the entire DbString is null, just set Value to DbNull
  • set the size if appropriate
  • set the type if appropriate
  • set the value using AsValue, or a (object)value.Value ?? DbNull if easier

The reason we can't put this into the library is that we can't ref Dapper directly because of the Dapper/Dapper.StrongName duality - hence we need to implement it in codegen

@DeagleGross
Copy link
Collaborator

questions:

  1. what does it mean "[DbValue] allows the size and type to be conveyed into DbParameter" (I can see both of them have System.Data.DbType member + DbParameter can handle strings (which DbString are))? Why is DbParameter in the context here?
  2. where is the code that copies entire files into the output?

@mgravell
Copy link
Member Author

  1. when passing some member .Foo into the DB, we do that via a parameter; by default we can only guess as to the type and other properties - but sometimes the details matter, so this tribute allows the .Size and .DbType of the parameter object to be controlled more explicitly

2 do you mean this? https://github.com/DapperLib/DapperAOT/blob/main/src/Dapper.AOT.Analyzers/CodeAnalysis/Writers/InterceptorsLocationAttributeWriter.cs#L24

@DeagleGross DeagleGross linked a pull request May 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants