You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Blog
{
BloggingContext _ctx;
public Blog(BloggingContext ctx) {
_ctx = ctx;
}
public int BlogId { get; set; }
public string Url { get; set; }
public int Rating { get; set; }
private Blog meField;
private Blog This => this;
private Blog MeFieldGet { get { return meField; } }
private static string UrlGet() { return "Fo' and 1=1 and 'o"; }
public int CountOthers() {
var me = this;
meField = this;
int s1 = _ctx.Blogs.Where(b => b != this).Count();
int s2 = _ctx.Blogs.Where(b => b != This).Count();
int s3 = _ctx.Blogs.Where(b => b != me).Count();
int s4 = _ctx.Blogs.Where(b => b != MeFieldGet).Count();
int s5 = _ctx.Blogs.Where(b => b != meField).Count();
return s1;
}
}
Using EF Core 2.2 the statements s2, s3, s4, s5 were translated to
SELECT COUNT(*) FROM "Blogs" AS "b"WHERE ("b"."BlogId" <> @__entity_equality_me_0_BlogId) OR @__entity_equality_me_0_BlogId IS NULL
Ef Core 3 translates s1, s2, s4, s5 to:
SELECT COUNT(*) FROM "Blogs" AS "b" WHERE "b"."BlogId" <> 99
Using literals instead of bind variables causes performance problems in Oracle because it destroys the statement cache. I don't know about other brands but I guess its the same problem too. Program.zip
The text was updated successfully, but these errors were encountered:
cello99d
changed the title
Free variables are no longer translated to bind variables if they defined by the type
Free variables are no longer translated to bind variables if they are defined by the type
Sep 2, 2019
Generated SQL in latest daily builds (Entity Framework Core 3.0.0-rc1.19429.10)
SELECTCOUNT(*)
FROM [Blogs] AS [b]
WHERE [b].[BlogId] <>99
exec sp_executesql N'SELECT COUNT(*)FROM [Blogs] AS [b]WHERE ([b].[BlogId] <> @__entity_equality_This_0_BlogId) OR @__entity_equality_This_0_BlogId IS NULL',N'@__entity_equality_This_0_BlogId int',@__entity_equality_This_0_BlogId=99
exec sp_executesql N'SELECT COUNT(*)FROM [Blogs] AS [b]WHERE ([b].[BlogId] <> @__entity_equality_me_0_BlogId) OR @__entity_equality_me_0_BlogId IS NULL',N'@__entity_equality_me_0_BlogId int',@__entity_equality_me_0_BlogId=99
exec sp_executesql N'SELECT COUNT(*)FROM [Blogs] AS [b]WHERE ([b].[BlogId] <> @__entity_equality_MeFieldGet_0_BlogId) OR @__entity_equality_MeFieldGet_0_BlogId IS NULL',N'@__entity_equality_MeFieldGet_0_BlogId int',@__entity_equality_MeFieldGet_0_BlogId=99
exec sp_executesql N'SELECT COUNT(*)FROM [Blogs] AS [b]WHERE ([b].[BlogId] <> @__entity_equality_meField_0_BlogId) OR @__entity_equality_meField_0_BlogId IS NULL',N'@__entity_equality_meField_0_BlogId int',@__entity_equality_meField_0_BlogId=99``
@cello99d - It is not easy to do that. Essentially we only see a constant in Expression tree. The only way we would make it parameter is to convert every constant ever appeared as a parameter. Which may not be desired behavior in all cases.
Using EF Core 2.2 the statements s2, s3, s4, s5 were translated to
SELECT COUNT(*) FROM "Blogs" AS "b"WHERE ("b"."BlogId" <> @__entity_equality_me_0_BlogId) OR @__entity_equality_me_0_BlogId IS NULL
Ef Core 3 translates s1, s2, s4, s5 to:
SELECT COUNT(*) FROM "Blogs" AS "b" WHERE "b"."BlogId" <> 99
Only acces to the local variable "me" in s3 ist still using a bind variable.
The edge case s1 was not translated as I would excpect in EF Core 2.2, see Query: Number is written into SQL Command Text instead of being a parameter when using 'this'
Using literals instead of bind variables causes performance problems in Oracle because it destroys the statement cache. I don't know about other brands but I guess its the same problem too.
Program.zip
The text was updated successfully, but these errors were encountered: