作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在处理我的第一个 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/
我需要创建一个从 C:\x 到 C:\xxx\yyy\zzz\aaa\bbb 的连接点(目录符号链接(symbolic link)),因为在将文件添加到这个目录,我无法控制目录结构。 我读到创建连接点
我是一名优秀的程序员,十分优秀!