【发布时间】:2019-10-11 02:08:33
【问题描述】:
我正在尝试向数据库添加组 ID,但我的数据模型的类型为“Group”,如何在不发送整个对象的情况下添加 GroupId
这是我的数据模型类
public class Tool : IObjectBase
{
public Group Group { get; set; } // My problem is here
public string Code { get; set; }
public string Name { get; set; }
public string Statut { get; set; }
public string StorageLocation { get; set; }
public string Description { get; set; }
public DateTime? CalibrationDate { get; set; }
public string InventoryNumber { get; set; }
public string SerialNumber { get; set; }
public string Contact { get; set; }
public string Image { get; set; }
public string StandardLoanPeriod { get; set; }
使用 Entity Framework 核心,我能够将此类作为表添加到数据库中,当然 ef 会将该组对象作为表中的 GroupId
所以现在在我的 Angular 应用程序中,我正在尝试使用此方法向数据库添加一个新工具
AddNewTool(form: NgForm) {
this.tool = {
Id : form.value.Id,
Code: form.value.Code,
Name: form.value.Name,
Description: form.value.Description,
Image: '',
Group: this.Group // Probleme is here
};
this.service.AddTool(this.tool).subscribe(
res => {
this.ToolToReload.emit(this.service.getTools());
this.toolRowInformation = null;
console.log(res);
form.resetForm();
} ,
err => {
console.log(err);
});
}
现在,每当我添加一个新工具时,它都会起作用,并且 groupId 会被该组填充,但同时,该组会添加到数据库中的组表中。
我尝试仅从 Angular 发送 GroupId,但我收到一条错误消息,提示该工具需要一个 Group 对象而不是字符串。
我的问题是是否可以在不发送整个组对象的情况下添加具有 groupId 的工具?
【问题讨论】:
标签: c# angular asp.net-core entity-framework-core asp.net-core-2.0