-
-
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
Question: How to return a nullable version of a fully qualified type #643
Comments
Hello @jbhelm. A quick remark on your code examples: the |
Yes of course, thanks! I've updated the example. |
1️⃣ 2️⃣ |
@jbhelm This should solve your question. |
@jbhelm |
@StefH Thanks for the fast turn around on this! Yes, if you create a preview I can try it out for our particular use case next week. |
@jbhelm https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json |
@StefH -- I gave this a try, thanks for publishing the preview. While it works well for LINQ to Objects, it does not work for LINQ to Entities, which is my use case. My queries can return nullable versions of value types that are not nullable in the model due to outer joins occurring on the database. Attempting to use the
Note that the same thing occurs with system value types such as DateTime:
In the case of the system types, the nullable cast operator of |
@jbhelm Example:
|
@jbhelm
You I'll create a new issue for item 3 and close this one and merge the PR to master. |
@StefH Thank you for your time on this! |
I am attempting to return a nullable version of a non-system value type (in this case an enum). According to the docs
{type}?(expr)
can be used to convert "Between the nullable and non-nullable forms of any value type". While this seems to work for system primitive types (Int32, etc), it does not work for fully qualified nullable types. Note that fully qualifying nullable system types (such asSystem.Int32?
) does not work either. I've tried various combinations of{type}?(expr)
andAs()
with quoted and unquoted type name, the question marks inside and outside the quotes, as well as adding theDynamicLinqType
attribute to the enum, but everything results in an error (see examples below). What is the proper way to return a nullable version of a non-system value type?This example is extremely simple for illustrative purposes; in my case these are much more complex dynamic LINQ strings being generated on the fly to execute against Linq to Entities on an Azure SQL database. Because it's executing on a database, it can return nullable values for properties that the model indicate are not nullable (due to outer joins, for example).
Related, but more of a feature request, would be a way to get a nullable version of an expression without needing to specify the type. Generally we don't know the actual type of the expression we're building, so we must go through a lot of code to determine that so we could pass it to
{type}?(expr)
-- but the dynamic LINQ library is also already doing all that as well to determine the underlying type. A method of getting a nullable version of whatever type the expression produces would be extremely helpful, something like?(expr)
ornullable(expr)
.Thank you -- this is a very useful library!
The text was updated successfully, but these errors were encountered: