Conversation
Closes dotnet#31552 (cherry picked from commit 484a3ed)
Closes dotnet#31552 (cherry picked from commit 484a3ed)
|
It's probably a bit late, but I wonder if |
|
@clement911 it's indeed too late as this has already shipped in 8.0.2; but I'm not seeing how EF.Inline or EF.Literal are better than EF.Constant; "constant" is the name used in the LINQ expression itself (ConstantExpression) - that can contain array or collection values just as well as non-collection ones. |
|
Thanks for your quick reply. I didn't realize that the Linq expression used the term I don't know. I find it strange to call a collection a 'constant'. I also find that 'Inline' would be more effective at conveying the fact that the purpose of the function is to avoid introducing a parameter. It's no big deal of course. |
Constant here simply implies "not a parameter or column" - it doesn't imply "scalar" or similar, as you seem to be understanding. In LINQ expression trees it's perfectly valid to write e.g. We use inline to convey another distinction: whether the value is constructed in-line within the query; this distinction doesn't make sense for ints/strings, but it does for arrays. To make things clearer: // This is a parameterized array
var array = new[] { 1, 2, 3 };
_ = ctx.Blogs.Where(b => array.Contains(b.Id).ToList();
// This produces an OPENJSON-based translation in 8.0, since a JSON array is the way to parameterize an array of values.
// This is a constant array:
var array = new[] { 1, 2, 3 };
_ = ctx.Blogs.Where(b => EF.Constant(array).Contains(b.Id).ToList();
// This translates to `b.Id IN (1, 2, 3)`.
// This is an inline array/collection:
_ = ctx.Blogs.Where(b => new[] { 1, 2, b.Id }.Contains(b.Id)).ToList();
// Note that the array very much isn't a constant - it even contains a column as an element. But it's specified in line.Hopefully that explains the terminology. |
Closes #31552