-
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 warning/code analyzer that mapping via function call produces different SQL (selects all columns) than inline mapping #30162
Comments
Btw solution to this performance issue is: |
@janseris are you saying that you're seeing more columns columns being projected out when using |
Yes But The If you do the mapping inline in the query, the projection is applied correctly - only required columns are selected in SQL. All columns are selected even if I select only the |
Related issue: #24509 Current issue is requesting a warning when it switches to client evaluation due to an opaque function. Linked issue is about throwing in that scenario. |
@janseris The call into Map is opaque to EF because nothing inside the function is included in the expression tree that EF is translating. In other words, EF has no way of knowing which properties are being selected. This isn't specific to EF, but rather the way LINQ works in .NET. If the function is to be translated, then it needs to contribute to the expression tree. One relatively easy way to do this is to write it in terms of IQueryables. For example: public static IQueryable<SeznamIDPrilohInfo> Map(this IQueryable<POZADAVEK> poz)
=> poz.Select(p => new SeznamIDPrilohInfo
{
VlastnikID = p.ID,
PrilohyIDs = (from s in p.Zaznam.Soubor select s.ID).ToList()
}); |
@ajcvickers It is not a bug. Thanks for the sample with IQueryable, I didn't think of that way of using it (without the penalty of silently selecting all columns and then dropping them) like that, will try out! |
@janseris in many cases, projecting out all the columns is what the user wants; even if in your particular case you don't want this, I don't think it would be appropriate to warn on this for everyone. |
Do you have an example? |
#24509 isn't quite the same as what we're discussing above - that would be a general opting out of any client evaluation (so queries would fail). If I understood you correctly, you were proposing a warning by default (without an opt-in) when a function is client-evaluated. In any case, if #24509 is what you want, then we do agree that makes sense, and we can close this issue as a dup of that. |
Note from triage: agreed that #24509 is sufficient here. |
Hi, I am sorry, I didn't have time to respond earlier, |
While selecting for photo IDs from the database for a list of ID of records,
we noticed that columns which are not a part of the projection are also selected even if the projection selects only IDs when the mapping is done via an external function.
I assumed the effect is the same as in LINQ to SQL (this (calling a function to map the data without a penalty) "worked" there I believe).
This issue happens when the mapping is called as a function and not directly in the query.
Using a mapping function is essential in large systems (DRY principle).
We noticed it when the table contained large byte array data - instead of kBs, hundreds of MBs were coming because all columns from all the tables were selected instead of only these requested in the projection in code.
I suggest a "feature" request: Add warning or intellisense suggestion for this behavior because it is a big deal.
Image showing generated SQL:
Code:
Schema with comments:
Thank you
The text was updated successfully, but these errors were encountered: