i have a little Problem with one of my Controllers.
Everytime i try to call some function with parameter a 500 is thrown and while debugging i can see that the function is not even called.
First my WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Entity>("Entities");
builder.EntitySet<DataTypes>("DataTypes");
builder.EntitySet<ObjectValue>("ObjectValues");
builder.EntitySet<Attributes>("Attributes");
builder.EntitySet<Objects>("Objects");
builder.Namespace = "EAVService.Controllers";
builder.Action("FullAttributes").Returns<IHttpActionResult>()
.CollectionParameter<Attributes>("Attributes");
builder.Action("FullValues").Returns<IHttpActionResult>()
.CollectionParameter<ObjectValue>("ObjectValue");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "odata",
model: builder.GetEdmModel());
config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
}
}
My Entity:
[Table("ObjectValue")]
public partial class ObjectValue
{
public ObjectValue()
{
}
[Key]
[Column(Order = 0)]
public int ObjectId { get; set; }
[Key]
[Column(Order = 1)]
[StringLength(50)]
public string Attribute { get; set; }
[StringLength(256)]
public string AttributeVal { get; set; }
public virtual Attributes Attributes { get; set; }
public virtual Objects Objects { get; set; }
}
and my Controller:
public class ObjectValuesController : ODataController
{
private EAVModel db;
public ObjectValuesController(IDbConnectionProvider provider)
{
db = new EAVModel(provider.GetDbConnection());
}
// GET: odata/ObjectValues
[EnableQuery]
public IQueryable<ObjectValue> GetObjectValues()
{
IQueryable<ObjectValue> query = db.ObjectValue.AsQueryable();
return query;
}
// GET: odata/ObjectValues(5)
[EnableQuery]
public IQueryable<ObjectValue> GetObjectValues([FromODataUri] string key)
{
IQueryable<ObjectValue> result = db.ObjectValue.Where(objectValue => objectValue.ObjectId == Convert.ToInt32(key)).AsQueryable();
return result;
}
.... }
The first Get Method is working fine.
When it comes to the second Get with a Parameter i get an Internal Server Error.
http://localhost:80/EAVServiceAPI/odata/ObjectValues(1)
Someone who can give me a hint what could be wrong?
Regards Andre