-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DerivesFrom not work on 7.9.0 #2092
Comments
Hi, |
@premiaware , Will be really great if you can please provide the same (repro and request) and we can fix it |
@premiaware This line in the stack trace piqued my interest:
Why does it refer to The sample code you shared above suggests the target framework for your application is NET Framework 4.* I tried that and everything works fine with the following application code:
// Models
public class Animal
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Dog : Animal
{
public string Breed { get; set; }
}
// Service configuration
public static void Register(HttpConfiguration config)
{
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Animal>("Animal");
modelBuilder.EntitySet<Dog>("Dogs");
modelBuilder.EntityType<Dog>().DerivesFrom<Animal>();
config.MapODataServiceRoute("odata", "odata", modelBuilder.GetEdmModel());
config.Select().Filter().Expand().OrderBy().Count().MaxTop(null);
config.EnsureInitialized();
}
// Controller
public class DogsController : ODataController
{
private readonly IList<Dog> dogs = new List<Dog>
{
new Dog { Id = 1, Name = "Butch", Breed = "Pitbull" }
};
public IHttpActionResult Get([FromODataUri] int key)
{
var dog = dogs.SingleOrDefault(d => d.Id.Equals(key));
if (dog == null)
{
return NotFound();
}
return Ok<Dog>(dog);
}
} Request:
Response {"@odata.context":"http://localhost/odata/$metadata#Dogs/$entity","Id":1,"Name":"Butch","Breed":"Pitbull"} |
Why does it refer to FHServices.Models.LandingPageImmobili? my class is public class TelefonoDescrittivo
Working only i change the or i declare TelefonoDescrittivo With Entity. Now i have downgrade the version and working well. |
Thanks @premiaware , Will be great if you can share a repro, your model and the request you are making so that we can get the exact scenario |
I have update my odata project to .net 6 using odata 8.0.12 and the previous issue return. to all working well |
I have this code on
On the controller i have this method
With version 7.8.3 all working Ok!!!
With version 7.9.0 the error is:
{"error":{"code":"","message":"An error has occurred.","innererror":{"message":"The 'ObjectContent
1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{"message":"The type 'FHServices.Models.UfficiExt' does not inherit from and is not a base type of 'FHServices.Models.LandingPageImmobili'. The type of 'KeySegments' must be related to the Type of the EntitySet.","type":"Microsoft.OData.ODataException","stacktrace":" in Microsoft.OData.UriParser.ExceptionUtil.ThrowIfTypesUnrelated(IEdmType type, IEdmType secondType, String segmentName)\r\n in Microsoft.OData.UriParser.KeySegment..ctor(IEnumerable
1 keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource)\r\n in Microsoft.OData.UriParser.ODataPathExtensions.AddKeySegment(ODataPath path, IEnumerable1 keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource)\r\n in Microsoft.OData.ODataWriterCore.AppendEntitySetKeySegment(ODataPath odataPath, Boolean throwIfFail)\r\n in Microsoft.OData.ODataWriterCore.EnterScope(WriterState newState, ODataItem item)\r\n in Microsoft.OData.ODataWriterCore.WriteStartNestedResourceInfoImplementation(ODataNestedResourceInfo nestedResourceInfo)\r\n in Microsoft.OData.ODataWriterCore.WriteStart(ODataNestedResourceInfo nestedResourceInfo)\r\n in Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteComplexProperties(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)\r\n in Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteResource(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)\r\n in Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n in Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n in Microsoft.AspNet.OData.Formatter.ODataOutputFormatterHelper.WriteToStream(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, IWebApiUrlHelper internaUrlHelper, IWebApiRequestMessage internalRequest, IWebApiHeaders internalRequestHeaders, Func
2 getODataMessageWrapper, Func2 getEdmTypeSerializer, Func
2 getODataPayloadSerializer, Func`1 getODataSerializerContext)\r\n in Microsoft.AspNet.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- Fine traccia dello stack da posizione precedente dove \u00e8 stata generata l'eccezione ---\r\n in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n in System.Web.Http.WebHost.HttpControllerHandler.d__22.MoveNext()"}}}}The text was updated successfully, but these errors were encountered: