【发布时间】:2013-10-03 14:01:12
【问题描述】:
我正在使用 C# 和 .NET Framework 4.0 开发 WCF RESTful Web 服务。还有一个 SQL Server 数据库,我使用 Entity Framework Code First 来访问它。
我在 SQL Server 上有这两个表:
我的应用程序用户的用户表。
User
{
userId,
name,
country
}
还有一张桌子来存储他们对某事的想法。
Thought
{
thoughtId,
userId,
description,
date
}
现在,我想在 iPhone 上显示UITableView 这些想法按日期排序。 UITableViewCell 将是这样的:
User.name
Thought.description
Thought.date
我可以这样返回 JSON 对象吗?(混合来自 user 和 thought 表的列)。
{
"thoughtId": "1",
"userId": "12",
"name": "John",
"description": "I'm thinking about you",
"date": "12/12/2012"
}
或者,在一次 GET 调用中获取此信息的最佳方式是什么?
最后,它的 URI 是什么? http://myhost/users/... 或 http://myhost/thoughts/...
我在某处读到,如果我使用http://myhost/users/...,我只能返回user 实体。
【问题讨论】:
-
您可以通过创建一个类来做到这一点,比如
UIViewDTO,其中 DTO 代表数据传输对象。这个类将包含所有必需的属性,它们是thoughtId、userId、name、description、date。
标签: c# json entity-framework rest