Allow IgnoreQueryFilters followed by select query

c# entity-framework-core soft-delete

Question

I am using ef core V2.1 with soft-delete.

I tried to fetch a student, with all his milestones record (include, some which were deleted), using the IgnoreQueryFilters() method.

But while I could do this:

applicationDbContex.Students
.IgnoreQueryFilters().Include("Milestones.Type")
.Where(...)
.ToArray();

When I tried to add a select statment after the where clause, It did not fetch the deleted milestones.

applicationDbContex.Students
     .IgnoreQueryFilters().Include("Milestones.Type").ToArray();         
     .Where(...)
     .Select(s => new {
         PersonalNumber = s.PersonalNumber,
         Milestones = s.Milestones 
     })

Here is the simplified models i am using:

public class Student {

    public ICollection<Milestone > Milestones {get; set;}
}

public class Milestone {
    ..
    public MilestoneType type {get; set;}
    ..
}

public class MileStoneType {
    ..
    public int Id {get; set;}
    ..
}

Any suggestions of what might be the problem?

EDIT:

I wish to state, that I use 'UseLazyLoadingProxies()' in startup.cs

 services.AddDbContext<ApplicationDbContext>(options => 
                options.UseLazyLoadingProxies()
                    .UseSqlServer(connectionString)
            );

It seems, that inorder to select query to work, I have to fetch a complete object , for instance the code works only, if I use the following code before:

 applicationDbContext.Soldiers.IgnoreQueryFilters()
            .Include("Milestones.Type").Load();
1
1
7/15/2019 7:41:12 AM

Popular Answer

you must call ignoreQueryFilter befor where and select

applicationDbContex.Students.IgnoreQueryFilters().Where(...)
     .Select(s => new {
         PersonalNumber = s.PersonalNumber,
         Milestones = s.Milestones 
     })
     .Include("Milestones.Type").ToArray();

and Include is useless when you use Select!

1
7/14/2019 10:33:46 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow