angular - Angular - 使用 ASP.NET Core Web API 从相关表中检索数据
问题描述
我在 ASP.NET Core Web API 中使用 Entity Framework Core 创建了许多具有一对多关系的相关表,如下所示:
public class code
{
public int id { get; set; }
public string productCode { get; set; }
public bool direction { get; set; }
public bool printFace { get; set; }
public int number { get; set; }
public int price { get; set; }
public bool color { get; set; }
public int typeId { get; set; }
public productType productType { get; set; }
public int sizeId { get; set; }
public productSize productSize { get; set; }
public int weightId { get; set; }
public productWeight productWeight { get; set; }
public int materialId { get; set; }
public productMaterial productMaterial { get; set; }
}
public class productWeight
{
public int id { get; set; }
[Required]
public int weight { get; set; }
public List<code> codes { get; set; }
}
public class productType
{
public int id { get; set; }
[Required]
public string typeName { get; set; }
public virtual List<code> codes { get; set; }
}
等等....
在 Angular 中,我试图从代码表及其相关表中检索数据
在 Angular 中,我有一个接口来模拟我想要获取的数据(如视图模型)
export interface IProduct {
id: number,
productCode: string,
direction: boolean,
printFace: boolean,
number: number,
price: number,
color: boolean,
sizeId: number,
typeId: number,
weightId: number,
materialId: number
}
但我做不好?我怎样才能在这里获取数据?
解决方案
我通过为每个表创建单独的接口并在主表(引用代码表的 Iproduct)中创建一个具有相关表示例类型的属性来解决此问题:对于 productMaterial 表:IproductMaterial.interface.ts:
export interface IproductMaterial{
id:number,
material:string
}
并在主界面:Iproduct.interface.ts"
export interface IProduct{
id:number,
productCode:string,
direction:boolean,
printFace:boolean,
number:number,
price:number,
color:boolean,
sizeId:number,
typeId:number,
weightId:number,
materialId:number,
**productMaterial:IproductMaterial**
}
通过这种方式,我可以轻松地显示数据
推荐阅读
- mysql - SQL 匹配从午夜开始计数的间隔
- sql - 基于 JOIN 和 2 个不同的列进行分组和排序
- c# - 带有自定义图像和文本的 WPF 按钮模板
- c++ - 矢量下标超出范围,如果 Bullers 不在窗口范围内,则尝试擦除子弹
- python - ModuleNotFoundError:没有名为“py_entitymatching”的模块
- php - PHP 中带有电子邮件的附件文件不会出现。有人能帮我吗?
- kubernetes - k8s-device-plugin:如何使用 docker 设置 deviceIDStrategy 值
- for-loop - (名称变量未定义)
- c# - 具有共享连接的内存数据库
- odoo - 我如何从 odoo13 qweb 报告中的菜单打印报告