Breeze JS中的连接表很多很多。如何获取data.results

时间:2013-11-20 20:27:40

标签: sql database breeze

我正在开发我的第一个Breeze Angular项目(.NET)。我正慢慢到那里,但在过去的两天里,我一直遇到以下问题。

我有3张桌子。

[产品] 1> m [ProductCategory] ​​m< 1 [分类]

ProductCategory是一个具有的Junction / Link表 ProductID和CategoryID作为外键。非常简单。

我需要生成一个CategoryI列表,其中ProductId = 3

任何想法如何使用Breeze EntityQuery做到这一点?

Breeze Query会是什么样子? 这是我所拥有的。

 var query = breeze.EntityQuery 
.from("Categorys") 
.expand(???)
.where("ProductCategory.ProductID", "==", 3);

所有三个表都正确建模,例如

public class Product_Category
{
    [Key]
    public int ID { get; set; }
    [Required]
    public int ProductID { get; set; }
     [Required]
    public int CategoryID { get; set; }
    [ForeignKey("CategoryID")]
    public Category Categories { get; set; }

    [ForeignKey("ProductID")]
    public Product Products { get; set; }

}

简单的SQL语句如下所示: -

     SELECT  ProductCategory.ProductID, ProductCategory.CategoryID,
     Categorys.CategoryName FROM            
                       ProductCategory INNER JOIN
                              Categorys ON 
ProductCategory.SubCategoryID = Categorys.SubCategoryID 
WHERE    (ProductCategory.ProductID = 3)

我意识到这是一个非常常见的要求,但我可能会尝试找不到解决方案。

更新

感谢Dominic,这是上述解决方案。如果其他人和我一样厚。

BREEZE

 var query = breeze.EntityQuery
.from("Products_Categories")
.expand("Categories")
.where("ProductID", "==", parseInt(prodid));

角度观点:

<div data-ng-repeat="item in ProductCategory">
    <div data-ng-repeat="sub in item.Categories">
        <span ng-show="sub.CategoryName.length">{{sub.CategoryName}}</span>
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

我认为你不能像

那样进行查询
var query = breeze.EntityQuery 
.from("Categorys") 
.expand(???)
.where("ProductCategory.ProductID", "==", 3);

但我相信你可以像

那样进行查询
var query = breeze.EntityQuery
.from("ProductCategory")
.expand("Categories")
.where("ProductId", "==", 3);

然后你必须遍历ProductCategories然后遍历其中的Categories。我不是100%肯定语法,因为出于某种奇怪的原因,客户端上的扩展在过去对我不起作用并且习惯了写。在creezeController中包含。但逻辑应该是相同的。