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

问题描述 投票:1回答:1

我正在开发我的第一个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)

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

UPDATE

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

微风

 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>
sql database breeze
1个回答
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中包含。但逻辑应该是相同的。

© www.soinside.com 2019 - 2024. All rights reserved.