Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Web API OData Returns Bad Request when ICollection encountered [837]

$
0
0

This is against the nightly builds of Web API OData, etc...

I've got an Account class, mapped using Entity Framework code first. In EF, Account has a Many to Many relationship to Role. Modeled as an ICollection<Role> property on the Account class.

When I try to retrieve Accounts through Web API OData, I get a 400 Bad Request. If I remove the Roles property, I can retrieve Accounts through Web API OData.

Relevant Entity Classes:
```
public abstract class Entity
{
public Guid Id {get;set;}
}
public class Account : Entity
{
public virtual ICollection<Role> Roles {get;set;}
}

public class Role : Entity
{
public virtual string Name {get;set;}
}
```

Relevant OData Configuration:
```
public static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
var accounts = builder.EntitySet<Account>("Accounts").EntityType;
accounts.HasMany(a => a.Roles);
return builder.GetEdmModel();
}
```
Comments: That did it. I was trying to do things incrementally and I noticed that a byproduct of calling ModelBuilder.EntitySet<Account>("Accounts") was that Role showed up in the Metadata, so I assumed that was enough to start working with Accounts. Thanks for the help, but as an editorial comment, I was expecting an exception on the server-side that told me what happened, but I'm not seeing anything. Using HttpSelfHostServer with IncludeErrorDetailPolicy.Always if that matters.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>