1

Closed

Can't update entity by WCF Data Service Client when it has readonly property

description

For example, define model:

public class Car
{
public int ID { get; set;}
public int WheelCount {
get {
return 4;
}
}
}

Build edm model:
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Car>("Cars");
return builder.GetEdmModel();

Generate client code by ASR, and write following code to post a new car:
        Container c = new Container(new Uri("http://localhost:50232/"));
        c.AddObject("Cars", new Car());
        c.SaveChanges();
Server side reports following exceptions:

System.ArgumentException occurred
HResult=-2147024809
Message=Property set method not found.
Source=mscorlib
StackTrace:
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
InnerException:
Closed Jan 18, 2013 at 10:07 PM by hongyes
Verified

comments

hongyes wrote Oct 10, 2012 at 9:10 PM

Controller code:
public class CarsController : ApiController
{
    public IEnumerable<Car> Get()
    {
        List<Car> cars = new List<Car>();
        cars.Add(new Car()
        {
            Id = 1,
            Model = "BMW",
            Name = "Mini"
        });

        return cars;
    }

    public void Post(Car car)
    { 

    }
}

HongmeiG wrote Oct 10, 2012 at 11:17 PM

We can avoid adding the read only property in conventional model builder if it is not for the query composition case.

HongmeiG wrote Oct 18, 2012 at 9:32 PM

Moving it out to post Build.