Azure的移动服务C#不会返回子实体 [英] Azure Mobile Services C# won't return child entities
问题描述
我真的击中基于Azure的移动业务新的C#砖墙,这真的很简单太:(
我不能为我的生命得到查询操作返回子属性值。
我已经修改这样的默认项目的待办事项:
I'm really hitting a brick wall with the new C# based Azure Mobile Services, and it's really simple too :( I can't for the life of me get the query operation to return child property values. I have the todo item of the default project modified like this:
public class TodoItem : EntityData
{
public TodoItem()
{
this.Numbers = new Collection<TodoItemNumbers>(new List<TodoItemNumbers>
{
new TodoItemNumbers{Value = 1},
new TodoItemNumbers{Value = 2},
new TodoItemNumbers{Value = 3},
new TodoItemNumbers{Value = 4},
new TodoItemNumbers{Value = 5},
});
}
public virtual ICollection<TodoItemNumbers> Numbers { get; set; }
public string Text { get; set; }
public bool Complete { get; set; }
}
然后我有这样定义的TodoItemNumbers类:
And then I have the TodoItemNumbers class defined like this:
public class TodoItemNumbers : EntityData
{
private int _value;
public int Value
{
get { return _value; }
set
{
_value = value;
Id = value.ToString();
}
}
public string TodoItemId { get; set; }
}
在TodoItemController我重写查询方法如下
In the TodoItemController I've overridden the Query method like this
protected override IQueryable<TodoItem> Query()
{
return base.Query().Include(x => x.Numbers);
}
当我做与小提琴手请求的这一切将返回数字财产。
在一个疯狂的时刻,我还修改了控制器的初始化方法,包括这样的:
None of this will return the Numbers property when I make a request with Fiddler. In a moment of madness I also modified the Initialize method of the controller to include this:
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
myContext context = new myContext();
context.Configuration.LazyLoadingEnabled = false;
context.Configuration.ProxyCreationEnabled = false;
DomainManager = new EntityDomainManager<TodoItem>(context, Request, Services);
}
请注意的延迟加载和代理的创建都被关闭。
有谁知道如何击败这个简单的场景?我觉得不舒服就这一个良好的共鸣。
Note the lazy loading and proxy creation have both been turned off. Does anyone know how to beat this simple scenario? I'm not feeling the good vibes on this one.
更新
因此,正如我在下面回答我能得到该服务通过在$添加扩展到查询返回的数据。但是现在我真的卡在获取客户到该参数添加到请求。它总是只返回基础数据。
Update So as I answered below I was able to get the service to return the data by adding in the $expand to the query. Now however I'm really stuck on getting the client to add that parameter to the request. It's always just returning the base data.
var data = await App.MobileService.GetTable<TodoItem>()
.ToListAsync();
将不会返回的子属性,并没有对结果类型
won't return the child properties, and there isn't an Include option on the result type
推荐答案
我的错误是不是真的把OData的部分进入方程。当我询问
My mistake was not really putting the OData part into the equation. As soon as I queried
http://localhost:51025/tables/todoitem?$expand=Numbers
而不是
http://localhost:51025/tables/todoitem
它奇迹般地出现了。现在我该怎样得到那个客户端API中遇到......?
更新
我这个code管理它在客户端
It magically appeared. Now how do I get that to come across in the client API...? Update I managed it on the client side with this code
var json =
await
App.MobileService.GetTable("TodoItem")
.ReadAsync("$expand=Numbers");
JsonConvert.DeserializeObject<TodoItem>(json.First.ToString());
但必须有一个更好的办法
But there has to be a better way
这篇关于Azure的移动服务C#不会返回子实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!