-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
2.2 breaks our queries and generates complex SQL #72
Comments
Here is on example in 1.4, where the only addition done by DynamicFilters is the DeletedOn = NULL in the Where clause:
Here is the same query with v2.2:
|
Please post the models and filters. I can't get enough information from only the sql query. Also your queries do not show any Dynamic Filter parameters at all so from looking at it right now, I would have to conclude that Dynamic Filters is not involved. So if that is not the actual query captured by SQL Profiler, please post that as well. |
We have what appears to be a similar problem with v2.3.0. In our case, we have a self-referencing entity defined as follows:
The filter is as follows:
In v1.4.11, the generated SQL was...
In 2.3.0, it is...
([Filter1].[Id] = [Extent2].[LastModifiedUserId]) should be ([Filter1].[LastModifiedUserId] = [Extent2].[Id]) and ([Project2].[Id] = [Extent3].[CreatorUserId]) should be ([Project2].[CreatorUserId] = [Extent3].[Id]) |
I updated from v1.4.11 to v2.4.0 the other day and suddenly a (only 1) very slow SQL query popped up. query_1.4.11.txt In code, I use a "where Id = 'guid'" filter and I map the EF entity to a DTO using AutoMapper's IQueryable extension. Version of AutoMapper is 4.1.1 in both scenario's above. Target DTO in this case is rather complex due to it's nested structure and 2 properties pointing to the same SQL table, but with v1.4.11 I never had any performance issues with it. If I compare the generated query in v2.4.0, I notice the use of "OUTER APPLY" statements. The v1.4.11 query doesn't have those. The example that @stormsjr1 posted is also an example of this behavior. Anyway, if I revert back to v1.4.11 all is good again, so it looks like the v2.4.0 version has something to do with it. |
Hi, Thx! |
Hello, |
Hello @ArnaudB88 , Thank you, I will try to reproduce this issue in the next few days and better understand what in the code has been modified to causing this issue. Best Regards, Jonathan |
Hello guys, Do anyone of you could help me to reproduce this issue Here is a code a tried to reproduce it with self-hierarchy as @stormsjr1 reported. If I could get a working example that causes the problem, I will be able to continue the investigation about the issue using System.Data.Entity;
using System.Linq;
using System.Windows.Forms;
using EntityFramework.DynamicFilters;
namespace Z.Lab
{
public partial class Form_Request_FilterLongQuery : Form
{
public Form_Request_FilterLongQuery()
{
InitializeComponent();
// CLEAR
using (var ctx = new EntityContext())
{
ctx.UserAccounts.RemoveRange(ctx.UserAccounts);
ctx.SaveChanges();
}
// SEED
using (var ctx = new EntityContext())
{
ctx.UserAccounts.Add(new UserAccount() { ColumnInt = 1, IsDeleted = false });
ctx.UserAccounts.Add(new UserAccount() { ColumnInt = 2, IsDeleted = true });
ctx.SaveChanges();
}
// TEST
using (var ctx = new EntityContext())
{
var list = ctx.UserAccounts
.Include(x => x.CreatorUser)
.Include(x => x.DeleteUser)
.Include(x => x.LastModifiedUser)
.ToList();
}
}
public class EntityContext : DbContext
{
public EntityContext() : base("CodeFirstEntities")
{
}
public DbSet<UserAccount> UserAccounts { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Filter("SoftDelete", (IAmSoftDeleted d) => d.IsDeleted, false);
modelBuilder.Types().Configure(x => x.ToTable(GetType().DeclaringType != null ? GetType().DeclaringType.FullName.Replace(".", "_") + "_" + x.ClrType.Name : ""));
base.OnModelCreating(modelBuilder);
}
}
public interface IAmSoftDeleted
{
bool IsDeleted { get; set; }
}
public class UserAccount : IAmSoftDeleted
{
public int ID { get; set; }
public int ColumnInt { get; set; }
public bool IsDeleted { get; set; }
public int? CreatorUserID { get; set; }
public UserAccount CreatorUser { get; set; }
public int? DeleteUserID { get; set; }
public UserAccount DeleteUser { get; set; }
public int? LastModifiedUserID { get; set; }
public UserAccount LastModifiedUser { get; set; }
}
}
} Best Regards, Jonathan |
I was able to recreate the issue in 2.3.0 with the following:
In v2.3.0, the generated query is as follows:
In 2.10, however, the dynamic SQL is correct:
So for my particular case, it appears to have been resolved somewhere between 2.3.0 and 2.10.0. |
Hello @stormsjr1 , Thank you for your example, I will try it this weekend and check what I can do. Best Regards, Jonathan |
Thank you @stormsjr1 , I tried your scenario and didn't understand why it was working until I realized you explicitly told the latest version was working correctly in this case. Your investigation may give me a hint to check when someone will be able to report a non-working code. If someone could provide me an example that doesn't work with the latest version, I will be happy to investigate it. Best Regards, Jonathan |
Hi @JonathanMagnan , Recently this bug became a big issue in one of our production systems. Thanks! |
Awesome @ArnaudB88 , Yes, one of my developers will look to your project. |
Any update on this bug yet? Thanks |
Unfortunately from what I remember, we started to look at it but abandoned to try to fix it at this moment. The v2.x had a lot of major changes to re-write query which is caused at the same time those kinds of performance issues. So when we tried to fix it, we caused a lot of side impact in the unit test project and never found the perfect solution. We are very open if someone could make a pull request with a fix but I don't think on our side we will put more time on it as we already spend several days trying to fix it and didn't make any progress. |
Thank you for the feedback. |
The project is open source @ArnaudB88 , You can do it on your side and provide a pull request if you find a solution. You must understand that my time or my developer time is not free or unlimited. Trying to fix this issue means that issue from other developers in other projects would not be fixed. So, unfortunately, we need to make some choices. |
We accidentally updated DynamicFilters to v2.2 through Nuget and all our many of our queries did no longer work. We are only applying an IsDeleted filter globally and with version 1.4, the queries only contained an additional Where clause, as was expected.
Now, with version 2.2, the queries are way longer and more complex, with several Outer Apply statements and the results are wrong compared to v1.4.
I will post specific examples once I had more time to investigate.
The text was updated successfully, but these errors were encountered: