1

Closed

Can't post derived type to base type's EntitySet

description

For example, define models:
[EntitySet("Vehicles")]
[DataServiceKey("Id")]
public class Vehicle
{
    public int Id { get; set; }

    public string Model { get; set; }

    public string Name { get; set; }

    public virtual int WheelCount { get; set; }
}

[EntitySet("Cars")]
[DataServiceKey("Id")]
public class Car : Vehicle
{
    public override int WheelCount
    {
        get
        {
            return 4;
        }
    }

    public int SeatingCapacity { get; set; }
}
Build model:
        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Vehicle>("Vehicles");
        builder.EntitySet<Car>("Cars");

        return builder.GetEdmModel();
Send data back to server:
DataServiceContext ctx = new DataServiceContext(new Uri(this.BaseAddress));
        ctx.AddObject("Vehicles", new Car() { SeatingCapacity = 5 });
        ctx.SaveChanges();
Get exception on server side:
Microsoft.Data.OData.ODataException occurred
HResult=-2146233079
Message=The property 'SeatingCapacity' does not exist on type 'WebStack.QA.Test.OData.Formatter.Vehicle'. Make sure to only use property names that are defined by the type.
Source=Microsoft.Data.OData
StackTrace:
   at Microsoft.Data.OData.ReaderValidationUtils.ValidateValuePropertyDefined(String propertyName, IEdmStructuredType owningStructuredType, ODataMessageReaderSettings messageReaderSettings, Boolean& ignoreProperty)
InnerException:
Closed Oct 10, 2012 at 10:17 PM by raghuramn
WCF DS generated proxy uses ResolveName and ResolveType method to resolve the type name in context.
Hongye confirmed that the generated proxy works fine. Closing this.

comments

HongmeiG wrote Oct 10, 2012 at 9:00 PM

This should work based on spec.