1. Create an IEdmModel that that has an entity in which a structural property that is nullable = false is added:
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("Namespace", "Resources");
model.AddElement(container);
EdmEntityType vehicle = new EdmEntityType("Namespace", "Vehicle", null, false, false);
vehicle.AddStructuralProperty("Status", EdmPrimitiveTypeKind.String, false); // this is an Enum on the type
EdmStructuralProperty property = vehicle.AddStructuralProperty("VehicleId", EdmPrimitiveTypeKind.String, false);
vehicle.AddKeys(property);
model.AddElement(vehicle);
model.SetAnnotationValue<ClrTypeAnnotation>(vehicle, new ClrTypeAnnotation(typeof(Vehicle)));
var vehicles = container.AddEntitySet("Vehicles", vehicle);
2. Implement Get() method that returns an IQueryable of type Vehicle. On the IQueryable, make sure HandleNullPropagation = HandleNullPropagationOption.False.
3. Host the OData Web API and make the following call: ~/Vehicles?$select=Status
Get the following:
{Table(Namespace.Vehicle).Select(Param_0 => new SelectSome`1() {ModelID = "cbe11608-9148-407f-b74d-80d477ac4f31", Container = new AutoSelectedNamedPropertyWithNext`1() {Name = "VehicleId", Value = Param_0.VehicleId, Next = new NamedProperty`1() {Name = "Status", Value = Convert(Param_0.Status)}}})}
Expected: No Value = Convert<Nullable<Enum>>(Param_0.Status)...
This causes issues, as must strip this out of the expression tree with a visitor if the LINQ Provider backend does not support Nullable<> types.
Comments: Hi, after investigating this bug, we do it this way in order to support Entity Framework. I don't think we should change this code in order to support a different backend. Overriding ApplyTo on the QueryableAttribute or on ODataQueryOptions and using an ExpressionVisitor to strip the Convert nodes is the best workaround. We could look into improving extensibility in this area, but I think that's a complete different topic.
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("Namespace", "Resources");
model.AddElement(container);
EdmEntityType vehicle = new EdmEntityType("Namespace", "Vehicle", null, false, false);
vehicle.AddStructuralProperty("Status", EdmPrimitiveTypeKind.String, false); // this is an Enum on the type
EdmStructuralProperty property = vehicle.AddStructuralProperty("VehicleId", EdmPrimitiveTypeKind.String, false);
vehicle.AddKeys(property);
model.AddElement(vehicle);
model.SetAnnotationValue<ClrTypeAnnotation>(vehicle, new ClrTypeAnnotation(typeof(Vehicle)));
var vehicles = container.AddEntitySet("Vehicles", vehicle);
2. Implement Get() method that returns an IQueryable of type Vehicle. On the IQueryable, make sure HandleNullPropagation = HandleNullPropagationOption.False.
3. Host the OData Web API and make the following call: ~/Vehicles?$select=Status
Get the following:
{Table(Namespace.Vehicle).Select(Param_0 => new SelectSome`1() {ModelID = "cbe11608-9148-407f-b74d-80d477ac4f31", Container = new AutoSelectedNamedPropertyWithNext`1() {Name = "VehicleId", Value = Param_0.VehicleId, Next = new NamedProperty`1() {Name = "Status", Value = Convert(Param_0.Status)}}})}
Expected: No Value = Convert<Nullable<Enum>>(Param_0.Status)...
This causes issues, as must strip this out of the expression tree with a visitor if the LINQ Provider backend does not support Nullable<> types.
Comments: Hi, after investigating this bug, we do it this way in order to support Entity Framework. I don't think we should change this code in order to support a different backend. Overriding ApplyTo on the QueryableAttribute or on ODataQueryOptions and using an ExpressionVisitor to strip the Convert nodes is the best workaround. We could look into improving extensibility in this area, but I think that's a complete different topic.