【发布时间】:2014-12-31 19:03:11
【问题描述】:
我在我的项目中使用 angular、breeze、WebApi、EF、SqlServer2008。 我有表 Articles 和表 ArticleComments,所以一篇文章可以有很多 articleComments 记录。
public class Article{
public int ArticleId { get; set; }
public string ArticleName { get; set; }
public string Description { get; set; }
public ICollection<ArticleComment> Comments { get; set; }
public ICollection<ArticleImage> ImagesList { get; set; }
...
}
public class ArticleComment
{
public int ArticleCommentId { get; set; }
public string CommentText { get; set; }
public int UserId { get; set; }
public int Rate { get; set; }
public DateTime CommentDate { get; set; }
public int ArticleId { get; set; }
public Article Article { get; set; }
public int Status { get; set; }
}
在客户端中,我需要获取带有 cmets、图像和其他链接实体的完整文章实体,但 cmets 需要仅用于选定的文章记录并且字段“status”== 1。
我尝试使用这样的查询
var pred = breeze.Predicate.create('articleId', 'eq', id)
.and('comments', 'any', 'status', '==', 1);
return EntityQuery.from("Articles")
.where(pred)
.expand('comments, imagesList...')
.toType(entityNames.article)
.using(manager).execute()
.to$q(querySucceded, self._queryFailed);
这将返回 article 的所有 cmets,但不会按状态字段过滤展开的表 ArticleComments。
【问题讨论】:
标签: javascript entity-framework breeze