Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OData客户端GetReadStreamAsync不工作_C#_Odata - Fatal编程技术网

C# OData客户端GetReadStreamAsync不工作

C# OData客户端GetReadStreamAsync不工作,c#,odata,C#,Odata,我使用生成一个客户端上下文来使用当前使用.NETCore2.1(OData7.2)的OData服务器。 受影响实体的元数据如下所示: <EntityType Name="Question" HasStream="true"> <Key> <PropertyRef Name="Language" /> <PropertyRef Name="QuestionRevisionId" /> </Key

我使用生成一个客户端上下文来使用当前使用.NETCore2.1(OData7.2)的OData服务器。 受影响实体的元数据如下所示:

 <EntityType Name="Question" HasStream="true">
    <Key>
        <PropertyRef Name="Language" />
        <PropertyRef Name="QuestionRevisionId" />
    </Key>
    <Property Name="QuestionRevisionId" Type="Edm.Int32" />
    <Property Name="Language" Type="Edm.String" Nullable="false" />
    <Property Name="CreatedDateTime" Type="Edm.DateTimeOffset" Nullable="false" />
    <Property Name="Author" Type="Edm.String" />
    <Property Name="ModifiedDateTime" Type="Edm.DateTimeOffset" Nullable="false" />
    <Property Name="Editor" Type="Edm.String" />
    <Property Name="TranslationStatus" Type="Edm.Int32" />
    <Property Name="IsDeleted" Type="Edm.Boolean" Nullable="false" />
    <NavigationProperty Name="QuestionRevision" Type="QM.AuthoringApi.OData.Entity.QuestionRevision">
        <ReferentialConstraint Property="QuestionRevisionId" ReferencedProperty="Id" />
    </NavigationProperty>
</EntityType>
运行代码:

var keys = new Dictionary<string, object>
{
    { "QuestionRevisionId", 9009 },
    { "Language", "en-US" }
};
var question = await apiReference.Questions.ByKey(keys).GetValueAsync();
apiReference.AttachTo("Questions", question); 
var thisIsNull = apiReference.GetReadStreamUri(question);
var stream = (await apiReference.GetReadStreamAsync(question, new DataServiceRequestArgs())).Stream;
var sr = new StreamReader(stream).ReadToEnd();
var keys=新字典
{
{“问题修正ID”,9009},
{“语言”,“en-US”}
};
var question=wait-apiereference.Questions.ByKey(key.GetValueAsync();
apiReference.AttachTo(“问题”,问题);
var thisIsNull=apreference.GetReadStreamUri(问题);
var stream=(wait apiereference.GetReadStreamAsync(问题,new dataServiceRequestStargs()).stream;
var sr=新的StreamReader(stream).ReadToEnd();
我得到这个错误:

System.ArgumentException:'此操作要求指定的 实体必须是媒体链接条目,并且ReadStreamUri必须可用。 但是,指定的实体不是媒体链接条目,也不是 没有有效的ReadStreamUri值。如果实体是媒体链接 条目,重新查询此实体的数据服务以获取有效的 ReadStreamUri值。(参数“实体”)

此异常最初是在 此调用堆栈: Microsoft.OData.Client.DataServiceContext.CreateGetReadStreamResult(对象, Microsoft.OData.Client.DataServiceRequestStargs、System.AsyncCallback、, 对象(字符串) Microsoft.OData.Client.DataServiceContext.BeginGetReadStream(对象, Microsoft.OData.Client.DataServiceRequestStargs、System.AsyncCallback、, (对象) System.Threading.Tasks.TaskFactory.FromAsyncImpl(System.Func,System.Func, 系统动作,TArg1,TArg2,目标, 系统。线程。任务。任务创建选项) System.Threading.Tasks.TaskFactory.FromAsync(System.Func,System.Func, TArg1、TArg2、对象) Microsoft.OData.Client.DataServiceContext.GetReadStreamAsync(对象, Microsoft.OData.Client.DataServiceRequestStargs) ConsoleApp1.Program.Main(字符串[])

文档和没有帮助我找出我遗漏了什么或做错了什么。

我在上打开了一个问题,当容器配置为无跟踪时,您无法访问流。至少使用了GetReadStreamAsync,到目前为止,这是我找到的唯一方法

container.MergeOptions = NoTracking;
请注意,如果在获取流之前尝试附加实体,则不会设置medialink,因此获取流将失败

container.MergeOptions = NoTracking;