AspNetCoreOData
AspNetCoreOData copied to clipboard
System.InvalidCastException: Unable to cast object of type 'Microsoft.OData.UnknownEntitySet' to type 'Microsoft.OData.Edm.IEdmEntitySet'.
I built a post endpoint. The data gets inserted into the database fine. But it throws the above error when returning: System.InvalidCastException: Unable to cast object of type 'Microsoft.OData.UnknownEntitySet' to type 'Microsoft.OData.Edm.IEdmEntitySet'.
However, doing a Get returns the object fine.
I'm using .Net 5.0. Microsoft.AspNetCore.OData 8.0.4
[HttpPost( "Persons({key})/PersonalAttributes" )]
public IActionResult CreatePersonalAttributeForPerson( int key , [FromBody] PersonAttribute personAttribute )
{
try
{
if( !ModelState.IsValid )
{
logModelStateError( );
return BadRequest( ModelState );
}
//Insert personAttribute into database
return Created( personAttribute );
}
catch( Exception ex )
{
_logger.LogError( ex , "{PersonId} {@PersonAttribute}" , key , personAttribute );
return StatusCode( StatusCodes.Status500InternalServerError );
}
}
Hi @cxc256, can you please share your CSDL for this? If personAttribute
is not a contained navigation property, then maybe the issue is that there is a missing navigation property binding in PersonalAttributes
?
Hey @cxc256 I have looked at the CSDL.
You dont have navigation property binding for PersonalAttributes
. You should have something similar to this in your csdl.
<EntityContainer Name="Container">
<EntitySet Name="Persons" EntityType="Namespace.Person">
<NavigationPropertyBinding Path="PersonalAttributes" Target="Persons"/>
...
...
<EntitySet />
<EntityContainer />
Alternatively PersonAttribute
should be contained
within Person
entity.
Cause of the issue pointed out