问题描述
我有一堂课
具有属性public virtual ICollection<Call> ReceivedCalls { get; set; }
的 Person
那么Call
是:
public class Call {
public int Id { get; set; }
public virtual Person Callee { get; set; }
public virtual ApplicationUser Caller { get; set; }
public DateTime TimeStamp { get; set; }
}
我有一个PersonController
和CallsController
(都是脚手架式WEB API OData控制器).
我可以通过以下链接获取人员及其呼叫(和谁呼叫):
http://localhost:17697/odata/Person?$expand=ReceivedCalls/Caller
我得到了漂亮的输出(不用担心,假数据):
{
"odata.metadata":"http://localhost:17697/odata/$metadata#Person","value":[
{
"ReceivedCalls":[
],"Id":1,"FirstName":"John","LastName":"Doe","CellNumber":"123-456-789","SecondaryPhoneNumber":"98873213","Email":null,"Address":"1street 2","BirthDate":"2014-10-02T00:00:00","Pesel":"312312312","Notes":"Lorem ipsum note","StatusId":null,"PersonalDataProcessing":false,"IsCalledRightNow":false,"CustomerStatusId":null,"NIP":null
},{
"ReceivedCalls":[
{
"Caller":{
"DisplayAnnouncmentNotification":true,"Email":"[email protected]","EmailConfirmed":false,"PasswordHash":"ABk0SI5boLt0YWE36G9PHGBMXEecl9eN3MQNHIlYy7nP8pHvr/IVsDVQ7oCtRuz/Uw==","SecurityStamp":"615f8ad3-ca19-42b9-9686-51597eef578c","PhoneNumber":null,"PhoneNumberConfirmed":false,"TwoFactorEnabled":false,"LockoutEndDateUtc":null,"LockoutEnabled":false,"AccessFailedCount":0,"Id":"812f907d-7079-433f-9503-b20e1d5a9ef7","UserName":"[email protected]"
},"Id":4,"TimeStamp":"2014-11-27T13:02:42.91"
}
但是知道我想知道呼叫者的Email
是什么
我尝试过:
http://localhost:17697/odata/Person?$expand=ReceivedCalls/Caller?$select=Email
但是我得到一个错误:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="en-US">
The query specified in the URI is not valid. Term 'ReceivedCalls/Caller?$select=Email' is not valid in a $select or $expand expression.
</m:message>
<m:innererror>
<m:message>
Term 'ReceivedCalls/Caller?$select=Email' is not valid in a $select or $expand expression.
</m:message>
<m:type>Microsoft.Data.OData.ODataException</m:type>
<m:stacktrace>
w Microsoft.Data.OData.Query.NonOptionSelectExpandTermParser.BuildExpandTermToken(Boolean isInnerTerm, PathSegmentToken pathToken)
w Microsoft.Data.OData.Query.SelectExpandTermParser.ParseExpand()
w Microsoft.Data.OData.Query.ODataUriParser.ParseSelectAndExpandImplementation(String select, String expand, IEdmEntityType elementType, IEdmEntitySet entitySet)
w System.Web.Http.OData.Query.SelectExpandQueryOption.get_SelectExpandClause()
w System.Web.Http.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)
w System.Web.Http.QueryableAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)
w System.Web.Http.QueryableAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
w System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
</m:stacktrace>
</m:innererror>
</m:error>
问题,我应该使用哪个链接为每个人访问Caller
?
编辑
它给了我
{
"odata.metadata":"http://localhost:17697/odata/$metadata#Person&$select=Email","value":[
{
"Email":null
},{
"Email":null
further DOWN there is:
},{
"Email":"[email protected]" // [email protected] is email of one of the Person
},{
是Person
的Email
而不是ApplicationUser
Caller
这应该有效
http://localhost:17697/odata/Person?$expand=ReceivedCalls($expand=Caller($select=Email))
我已经在TripPin示例站点上使用此网址尝试过
http://services.odata.org/V4/(S(0yzzniu3ezyzy1ragcduis3n))/TripPinServiceRW/People?$expand=Friends($expand=Trips($select=TripId))
I have a class:
Person
which has property public virtual ICollection<Call> ReceivedCalls { get; set; }
Then the Call
is :
public class Call {
public int Id { get; set; }
public virtual Person Callee { get; set; }
public virtual ApplicationUser Caller { get; set; }
public DateTime TimeStamp { get; set; }
}
I have a PersonController
and CallsController
(both are scaffolded WEB API OData controllers).
I can fetch people and their calls (and who called) by the link:
http://localhost:17697/odata/Person?$expand=ReceivedCalls/Caller
and I get pretty output(no worry, fake data):
{
"odata.metadata":"http://localhost:17697/odata/$metadata#Person","value":[
{
"ReceivedCalls":[
],"Id":1,"FirstName":"John","LastName":"Doe","CellNumber":"123-456-789","SecondaryPhoneNumber":"98873213","Email":null,"Address":"1street 2","BirthDate":"2014-10-02T00:00:00","Pesel":"312312312","Notes":"Lorem ipsum note","StatusId":null,"PersonalDataProcessing":false,"IsCalledRightNow":false,"CustomerStatusId":null,"NIP":null
},{
"ReceivedCalls":[
{
"Caller":{
"DisplayAnnouncmentNotification":true,"Email":"[email protected]","EmailConfirmed":false,"PasswordHash":"ABk0SI5boLt0YWE36G9PHGBMXEecl9eN3MQNHIlYy7nP8pHvr/IVsDVQ7oCtRuz/Uw==","SecurityStamp":"615f8ad3-ca19-42b9-9686-51597eef578c","PhoneNumber":null,"PhoneNumberConfirmed":false,"TwoFactorEnabled":false,"LockoutEndDateUtc":null,"LockoutEnabled":false,"AccessFailedCount":0,"Id":"812f907d-7079-433f-9503-b20e1d5a9ef7","UserName":"[email protected]"
},"Id":4,"TimeStamp":"2014-11-27T13:02:42.91"
}
But know I would like to know what is an Email
of the caller,
I tried that:
http://localhost:17697/odata/Person?$expand=ReceivedCalls/Caller?$select=Email
but I get an error:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="en-US">
The query specified in the URI is not valid. Term 'ReceivedCalls/Caller?$select=Email' is not valid in a $select or $expand expression.
</m:message>
<m:innererror>
<m:message>
Term 'ReceivedCalls/Caller?$select=Email' is not valid in a $select or $expand expression.
</m:message>
<m:type>Microsoft.Data.OData.ODataException</m:type>
<m:stacktrace>
w Microsoft.Data.OData.Query.NonOptionSelectExpandTermParser.BuildExpandTermToken(Boolean isInnerTerm, PathSegmentToken pathToken)
w Microsoft.Data.OData.Query.SelectExpandTermParser.ParseExpand()
w Microsoft.Data.OData.Query.ODataUriParser.ParseSelectAndExpandImplementation(String select, String expand, IEdmEntityType elementType, IEdmEntitySet entitySet)
w System.Web.Http.OData.Query.SelectExpandQueryOption.get_SelectExpandClause()
w System.Web.Http.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)
w System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)
w System.Web.Http.QueryableAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)
w System.Web.Http.QueryableAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
w System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
</m:stacktrace>
</m:innererror>
</m:error>
Question What link should I use to access the Caller
for every person?
EDIT
It gave me:
{
"odata.metadata":"http://localhost:17697/odata/$metadata#Person&$select=Email","value":[
{
"Email":null
},{
"Email":null
further DOWN there is:
},{
"Email":"[email protected]" // [email protected] is email of one of the Person
},{
which is Email
of a Person
not of a Caller
which is ApplicationUser
This should work
http://localhost:17697/odata/Person?$expand=ReceivedCalls($expand=Caller($select=Email))
I have tried it on the TripPin example site with this url
http://services.odata.org/V4/(S(0yzzniu3ezyzy1ragcduis3n))/TripPinServiceRW/People?$expand=Friends($expand=Trips($select=TripId))
这篇关于如何从扩展属性中选择属性? ReceivedCalls/Caller?$ select =电子邮件在$ select或$ expand表达式中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!