【发布时间】:2015-08-14 22:48:46
【问题描述】:
首先,这不完全是其他几十个帖子的重复,我已经尝试了所有这些帖子,但没有一个有效。
我的模型包含的值比我的 Web api 消费者需要的多。
public class Publication
{
[Key]
public int PublicationID { get; set; }
public string PublicationTitle { get; set; }
public string Frequency { get; set; }
public DateTime NextIssueDate { get; set; }
public DateTime SpaceDeadline { get; set; }
public DateTime MaterialsDeadline { get; set; }
public DateTime CreatedDt { get; set; }
public string CreatedBy { get; set; }
public DateTime UpdatedDt { get; set; }
public string UpdatedBy { get; set; }
}
我只想说几个要在 API 中传递的字段。我已经尝试过这段代码,但它没有在 Json 结果中省略说 UpdateBy ,而是以空值返回它。我该如何摆脱它?我已经尝试了几十种变体,但它们要么无法编译,要么无法返回结果。
public IQueryable<Publication> GetPublications()
{
return db.Publications
.ToList()
.Select(p => new Publication {
PublicationID = p.PublicationID,
PublicationTitle = p.PublicationTitle,
Frequency = p.Frequency,
NextIssueDate = p.NextIssueDate
})
.AsQueryable();
}
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-web-api