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

QueryBuilder missing AppendLine( FormattableString ) #9

Closed
terryaney opened this issue Nov 18, 2023 · 5 comments
Closed

QueryBuilder missing AppendLine( FormattableString ) #9

terryaney opened this issue Nov 18, 2023 · 5 comments
Labels
question Further information is requested

Comments

@terryaney
Copy link
Contributor

terryaney commented Nov 18, 2023

Could be by design and that is fine, but in DapperQueryBuilder, I could do:

qb.AppendLine( fileKey != null
	? (FormattableString)$" AND f.UID = {fileKey}"
	: $" AND fo.Name = {folder:varchar(200)} AND f.Name = {fileName:varchar(200)}"
);

However, I get Argument 1: cannot convert from 'System.FormattableString' to 'InterpolatedSql.IInterpolatedSql' in InterpolatedSql. I've found a few workarounds so maybe that is intention. Let me know if method was missed or if I one of the workarounds below is the desired pattern going forward:

Workaround 1 - no Ternary operator

if ( fileKey != null )
{
	qb.AppendLine( $" AND f.UID = {fileKey}" );
}
else
{
	qb.AppendLine( $" AND fo.Name = {folder:varchar(200)} AND f.Name = {fileName:varchar(200)}" )
}

Workaround 2 - Found this method I've never used before

qb.AppendFormattableString( fileKey != null
	? (FormattableString)$" AND f.UID = {fileKey}"
	: $" AND fo.Name = {folder:varchar(200)} AND f.Name = {fileName:varchar(200)}"
);

Workaround 3 - Appending via += seems to compile

qb += fileKey != null
	? (FormattableString)$" AND f.UID = {fileKey}"
	: $" AND fo.Name = {folder:varchar(200)} AND f.Name = {fileName:varchar(200)}";

I'm going to test with number 3, but please advise. Thanks.

@Drizin
Copy link
Owner

Drizin commented Dec 4, 2023

How did it go?

I think both 2 and 3 are good options.

Previously methods were just named "Append/AppendLine" (and would always take a FormattableString) but since I've introduced InterpolatedStringHandlers I had some issues with ambiguous overloads, and therefore in some places I had to use this explicitly-named AppendFormattableString (which does NOT add a leading linebreak, so you might want to start your strings with \n).

@Drizin Drizin added the question Further information is requested label Dec 4, 2023
@terryaney
Copy link
Contributor Author

terryaney commented Dec 4, 2023

OK. If by design, will use method 3. Compiles, writing some integration tests to my project so I can run/confirm nothing changes in results :) Will let you know.

@Drizin
Copy link
Owner

Drizin commented Feb 26, 2024

@terryaney Did it work? Can we close this?

@terryaney
Copy link
Contributor Author

Pulled away, but actually was just working on finishing all my integration tests. You can close this and I'll reopen if the issue presents itself?

@Drizin Drizin closed this as completed Feb 26, 2024
@terryaney
Copy link
Contributor Author

@terryaney Did it work? Can we close this?

Yes it worked :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants