gpt4 book ai didi

sql - Breeze JS 中的联结表多对多。如何获取data.results

转载 作者:搜寻专家 更新时间:2023-10-30 23:11:08 24 4
gpt4 key购买 nike

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

我有 3 个表。

[产品] 1>m [产品类别] m<1 [类别]

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

我需要生成 ProductId = 3 的类别列表

知道我如何使用 Breeze EntityQuery 做到这一点吗?

Breeze 查询会是什么样子?据我所知。

 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));

角度 View :

<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>

最佳答案

我不认为你可以像这样查询

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% 确定语法,因为出于某种奇怪的原因,客户端扩展在过去对我不起作用并且习惯于编写 .Include in breezeController,但逻辑应该是相同的。

关于sql - Breeze JS 中的联结表多对多。如何获取data.results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20106311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com