0

OData(5.5.0-alpha2) で Asp.Net Web Api を使用します。そして、私はモデルを持っています:

public class Model
{
    public List<Event> Events { get; set; }
    public List<User> Subscribers { get; set; }
    public User Owner { get; set; }
    ....
}

コントローラーでのアクション:

[Queryable(AllowedQueryOptions = AllowedQueryOptions.All, MaxAnyAllExpressionDepth = 10, MaxExpansionDepth = 10)]
public override IQueryable<EventsChannel> Get()
{
    return Repository.Models.AsQueryable();
}

Repository.Models は、含まれているプロパティを持つすべてのモデルを提供します。

所有者の展開でデータを取得しようとすると:

http://site.com/odata/Models()?$expand=Owner

すべて順調です。しかし、イベントを取得しようとすると:

http://site.com/odata/Models()?$expand=Events

それは私に例外をスローします:

The argument must be of type 'IEnumerable'.&#xD; Parameter name: graph

List を IEnumerable に変更できません。また、List が IEnumerable であるのに、なぜこのように表示されるのでしょうか?

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code />
  <m:message xml:lang="en-US">An error has occurred.</m:message>
  <m:innererror>
    <m:message>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/atom+xml; charset=utf-8'.</m:message>
    <m:type>System.InvalidOperationException</m:type>
    <m:stacktrace></m:stacktrace>
    <m:internalexception>
      <m:message>The argument must be of type 'IEnumerable'.&#xD;
Parameter name: graph</m:message>
      <m:type>System.ArgumentException</m:type>
      <m:stacktrace>   at System.Web.Http.OData.Formatter.Serialization.ODataCollectionSerializer.CreateODataValue(Object graph, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEdmTypeSerializer.CreateProperty(Object graph, String elementName, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralProperty(IEdmStructuralProperty structuralProperty, EntityInstanceContext entityInstanceContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralPropertyBag(IEnumerable`1 structuralProperties, EntityInstanceContext entityInstanceContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObjectInline(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteExpandedNavigationProperty(KeyValuePair`2 navigationPropertyToExpand, EntityInstanceContext entityInstanceContext, ODataWriter writer)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteExpandedNavigationProperties(IDictionary`2 navigationPropertiesToExpand, EntityInstanceContext entityInstanceContext, ODataWriter writer)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObjectInline(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)&#xD;
   at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.&lt;&gt;c__DisplayClassa.&lt;WriteToStreamAsync&gt;b__9()&#xD;
   at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)&#xD;
--- End of stack trace from previous location where exception was thrown ---&#xD;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xD;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xD;
   at System.Web.Http.WebHost.HttpControllerHandler.&lt;WriteBufferedResponseContentAsync&gt;d__10.MoveNext()</m:stacktrace>
    </m:internalexception>
  </m:innererror>
</m:error>
4

0 に答える 0