-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Add IQueryable.OfType support to ExpressionParser. #248
Comments
Can't you just use: var oftype = context.Base.OfType<Derived>().Where("DerivedProperty > 10"); |
I can do that. But i cant do this: |
I see, I'll take a look to implement this. |
Try latest version from MyGet 1.0.10-ci-1952 Use it like: var config = new ParsingConfig
{
AllowNewToEvaluateAnyType = true
};
context.ComplexDtos
.Select(config, "ListOfBaseDtos.OfType(\"ConsoleAppEF2.Database.TestDto\").Where(Name == \"t\")"); |
@dsidedp Can you please do some tests? |
I did some with 1.0.11-ci-1955 on production model I have. From all tests i ran, only one failed - when I tried to use OfType with context keywords. Besides of single issue, I can think about couple of other things related to this:
And one more - Thanks a lot for fast response to feature request! |
|
Reference NavigaionAs an example of valid linq query with reference navigation: Basically, by doing this linq is adding ConvertExpression(x, DerivedType) as input for PropertyExpression. ResolveTypesBySimpleNameHaving the ability to opt out from internal type resolver using config switch looks good to me. As another option (or extension), you can do something similar to what you have with CustomTypeProvider. OfTypeNormal linq for Another challenge here would be queries with like So it seems to me that allow mixing like this should be denied, and if OfType allied to "it" - there should be no "and"s and "or"s on the same level. Here are couple of examples: |
ResolveTypesBySimpleName : I've created a new issue for this #252 and will create a new PR for this. OfType : to get |
OfType I tried to implement this: bool isOfType = context.BaseDtos.Any(b => b is TestDto);
bool isOfTypeDynamic = context.BaseDtos.Any(config, "OfType(\"ConsoleAppEF2.Database.TestDto\")"); However the dynamic code does not work because I don't know the real type from the See also this code: |
Ok, I see. How about "Is" operator? In this case "it.OfType" can be replaced with: And with support of reference cast (cast object to derived type): Considering what i was saying earlier regarding restrictions of OfType applied to "it", having "Is" operator seems to be good replacement. |
I did send you invite for gitter chat; it's easier to talk. |
I didin't use gitter before, so just got registered there. You will probably need to send invite again. Also, I looked at commented out code again, and it seems to be OK. |
@dsidedp I think all is resolved now? Can I merge to master? |
Looks good to me. |
OK, I'll merge to master and create a new NuGet new version will be communicated here in this issue... |
Official NuGet 1.0.11 is uploaded. |
EF Core allows to use OfType to filter derived entities from base collections
It would be great to have this supported as part of Where clause, e.g. :
ctx.Set<Base>.Where("OfType("\Derived\").Any(DerivedProperty> 10)")
The text was updated successfully, but these errors were encountered: