-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add RelationalDbSet for raw query #1734
Conversation
@@ -11,7 +11,7 @@ | |||
|
|||
namespace Microsoft.Framework.DependencyInjection | |||
{ | |||
internal static class ServiceProviderExtensions | |||
public static class ServiceProviderExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need these, share them, rather than making this public.
Can you please describe what's in this change? |
@@ -148,5 +158,82 @@ var keyFactory | |||
Expression.Call(queryMethodInfo, queryMethodArguments), | |||
_readerParameter)); | |||
} | |||
|
|||
protected Expression VisitRelationalCustomQueryable(string sql, Type elementType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't duplicate the code below. Refactor both into something that pivots on the source table expr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we want an optional expression parameter so the existing code path can use the element type as it was but we still have a way to pass in the query string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just extract a new method and call it from both places. It may be DRY'er to have the new method take a Func as a factory for the table expr. but I would see what it looks like to just build the table expr. externally first.
Updated based on PR feedback |
|
||
public override string ToString() | ||
{ | ||
return base.ToString() + string.Join(", ", _annotatable.Value.Annotations.Select(annotation => annotation.Value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the formatting - e.g. space between base.ToString() and annotations, maybe wrap annotations in some kind of parenthesis.
0f4b83e
to
71fde95
Compare
More updates based on PR input |
|
||
SELECT [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[CustomerID], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] | ||
FROM ( | ||
SELECT * FROM Customers WHERE Customers.City = 'Seattle' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the raw SQL query contains multiple lines, will they all be indented the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't any logic in place to do this right now, did we want to try?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be easy if you use a StringReader to read each line and append to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we need to worry about literal line-breaks in quoted strings etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can do that - at least in TSQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is not too bad, but the alternative is to not worry about it at all and not try to indent raw SQL.
|
||
public override string ToString() | ||
{ | ||
return Sql + " " + Alias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"(" + Sql + ") AS " + Alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't seem very DRY to me, since this would be guessing at the interpretation of the SQL generator that consumes this object.
The current implementation is consistent with the other TableExpressions, but we could revisit this if it's important / useful enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for debugging so do whatever makes it clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added #1795 to track this
Updated based on feedback |
|
||
public virtual Annotation AddAnnotation([NotNull] string annotationName, [NotNull] string value) | ||
{ | ||
Check.NotNull(annotationName, nameof(annotationName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotEmpty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a stronger constraint than we have on Annotatable
itself, do we want to update that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, seems like an oversight.
Rebased, squashed, updated, and ready for another pass.
|
After talk with @anpete, looking at using QueryAnnotations to store the FromSql string and parameters. |
This is mostly a rewrite so a new PR. |
Closing PR, will make a new one for the next revision. |
Add custom relational queries off of DbSet to provide functionality for #624
@ajcvickers @anpete @divega