Comments (19)
What happens when you call "context.Instructors.ToList()"? Is it not filtering on IsDeleted or throwing an error?
from entityframework.dynamicfilters.
I set up a test using the models and filter exactly as you posted here. Everything is working correctly for me. The filter is applied when I query from Students, Instructors, and People. I'm gong to need some more information from you about what exactly is the problem you are seeing as you didn't state what the problem is, just that you are having one... :)
from entityframework.dynamicfilters.
I added two instructor records to the Db then marked the last record as deleted.
It threw and exception. Property "IsDeleted" not found on EdmType Instructor.
from entityframework.dynamicfilters.
I just pushed up the test I created to try to duplicate this. Can you take a look at that and compare it to what you are doing? We must be doing something different since it works for me... Or if you can prepare a full solution to demonstrate it and email it to me ([email protected]), that would work too.
from entityframework.dynamicfilters.
Let me prep up a solution. I will email it soon as i'm done. :)
from entityframework.dynamicfilters.
I am also having the same problem, did you ever find a solution to this?
from entityframework.dynamicfilters.
No, I am not able to reproduce the problem with the models TefoT4 posted and still waiting on a full solution that demonstrates the problem. If you have more information on how to reproduce it, please post it and I'll take a look.
from entityframework.dynamicfilters.
My setup is slightly different but should work the same. I get the error found in LambdaToDbExpressionVisitor line 248 formatted like this: Property Deleted not found in Entity Type BaseModel
Now, that is strange to me because I do not see my setup as accessing entities outside of the main model (if this is the case would you be happy for me to pull the code and implement that functionality)?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Filter("SoftDelete", (BaseModel x) => x.Deleted == null);
base.OnModelCreating(modelBuilder);
}
public class BaseModel
{
public DateTime? Created { get; set; }
[MaxLength(32)]
public String CreatedBy { get; set; }
public DateTime? Updated { get; set; }
[MaxLength(32)]
public String UpdatedBy { get; set; }
[Index]
public DateTime? Deleted { get; set; }
}
public class Person : BaseModel
{
public int Id { get; set; }
[Required, Display(Name = "First Name"), MaxLength(32)]
public string FirstName { get; set; }
[Display(Name = "Middle Name"), MaxLength(64)]
public string MiddleName { get; set; }
[Required, Display(Name = "Last Name"), MaxLength(32)]
public string LastName { get; set
}
[Table("Residents")]
public class Resident : Person
{
[Required, MaxLength(4)]
public string Title { get; set; }
[MaxLength(32), Display(Name = "Maiden Name")]
public string MaidenName { get; set; }
[MaxLength(32), Display(Name = "Famailiar Name")]
public string FamiliarName { get; set; }
[Required, MaxLength(1)]
public string Gender { get; set; } // M or F
[Display(Name = "Date of Birth"), DataType(DataType.Date)]
public DateTime? DateOfBirth { get; set; }
}
I get the above error whenever I try to query anything, Residents, People or any other entity - so on reflection this might not be directly related to the TPT setup and more about the use of BaseModel as a class rather than an interface, either way it feels like what I am doing should work/should be supported?.
I wrote this up pretty quickly before work, I will happily spend some time to help you reproduce the error I get if this doesn't help later today.
Thanks,
Tom.
from entityframework.dynamicfilters.
After further investigation the problem seems to be that the 'Resident' entity doesn't have the properties that 'BaseModel' has because it is inheriting them from 'Person'. 'Person' does have the properties from 'BaseModel'. So when the code tries to find the 'Deleted' property on 'Resident' it just falls over and dies.
This still seems strange because you can obviously access the 'Deleted' property in the linq queries.
from entityframework.dynamicfilters.
I tried reproducing this using the models and filter exactly as you posted and it works fine for me... What database and which version of EF are you using (I tried with 6.1.2 and 6.1.3)? I may need you to package up a full solution and email it to me ([email protected]) so I can figure out what's different.
from entityframework.dynamicfilters.
Ef 6.1.3 & sql server
from entityframework.dynamicfilters.
Could you send me what you did to reproduce ([email protected])?
from entityframework.dynamicfilters.
The problem seems to be caused by you having a DbSet created in your DbContext in addition to the DbSet. If you remove that, it works fine. I'm not sure yet why that causes a problem but I'll dig into it and figure it out. It might be a couple days though - I'm actually on vacation right now and traveling tomorrow.
from entityframework.dynamicfilters.
"DbSet created in your DbContext in addition to the DbSet" - Sorry, what do you mean? Don't I have to have my DbSet's defined in my DbContext?
from entityframework.dynamicfilters.
In your ApplicationDbContext class, you have these 2 lines:
public DbSet<Person> People { get; set; }
public DbSet<Resident> Residents { get; set; }
At least in the project you sent me, "People" is not referenced so you can safely remove it. But, that obviously changes your table structure and will result in a single Residents table instead of 2 tables which is probably not what you're going for.
Just a theory/guess, but... I think the use of TPT between People and Residents and the inheritance (non-TPT) between People and BaseModel is what is causing the issue. But no idea if it's something inside EF or with my filters. If you want to work around this (for now at least), you could move everything from BaseModel into People, create an IBaseModel interface for those fields, and then create the filter against that interface.
from entityframework.dynamicfilters.
That is exactly what I thought too... i'll give that work around you suggest for now, i'll let you know how it goes.
from entityframework.dynamicfilters.
I am still getting the same problem when I create IBaseModel and add the implementation to Person.
EDIT: could you send me what you did to test it? I can't get mine to work.
from entityframework.dynamicfilters.
Found the problem. Fix is pushed and NuGet has been updated.
The problem was being caused by TPT inheritance. Basically, when you query out "Residents", EF is automatically including a join against Person. Since both of those C# classes inherit the deleted filter, it was being applied by each of those 2 DbScanExpressions. And where the Residents C# class has the Deleted property, the Residents database table does not - hence the error. So the fix was to detect this and not apply the filter where it should not be.
Another note (and this may apply more to @TefoT4): Because of how the queries are parsed, the problem is only hit if you create a filter like this:
modelBuilder.Filter("IsDeleted", (IEntity e) => e.IsDeleted == false)
as opposed to this:
modelBuilder.Filter("IsDeleted", (IEntity e) => e.IsDeleted, false)
The difference is one uses a parameter and the other does not. When I changed his filter to the non-parameter version, I hit the same problem with his models. I'm wondering if the trouble reproducing that case was because of this.
from entityframework.dynamicfilters.
Great! Thank you for fixing this so fast. Hope you had a good holiday.
EDIT: Just tested this, works a perfectly. Thank you again.
from entityframework.dynamicfilters.
Related Issues (20)
- [Oracle EF 6.2] System.MissingMethodException HOT 1
- Conditional filter not working with EntityFramework6.Npgsql 3.2.1.1 HOT 6
- Support for EF 6.3 and netstandard HOT 7
- Context.Set<T>().Find(keyValues) And Use Context.Filter<Interface>() after, HOT 3
- EntityCommandCompilationException when using .Include() on class with subclass HOT 2
- Entity Framework Dynamic Filters not working in dot net core HOT 3
- Another way to initialize filters besides calling modelBuilder.Filter? HOT 1
- Enum-of-byte is unnecessarily cast to int HOT 6
- IsFilterEnabled returns true for non-existent filter HOT 1
- Cannot use a DBContext property in a condition for a dynamic filter. Value dosen't update after initial execution. HOT 1
- Problem creating Filter HOT 2
- Compatibility issue with bulk operations (Z.EntityFramework.Extensions) HOT 6
- Why filters should come last in the model creation? HOT 11
- Filter with claim HOT 3
- Compile error with package reference HOT 2
- Concurrency error when PreventDisabledFilterConditions is called HOT 4
- Issue with dynamic filter applied on eager loading with many-to-many relationship entities using MySQL
- Issue occur when dynamic filter is applied on eager loading with many-to-many relationship entities for MySQL HOT 8
- Filter decoder HOT 1
- ConcurrentDictionary is breaking my Oracle 11g unit tests HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityframework.dynamicfilters.