【发布时间】:2021-09-20 11:02:14
【问题描述】:
我正在使用.net core,我想在数据库中进行关联。
一个客户可以有多个“治疗”记录。我怎样才能列出它? 所以我想列出一个客户的治疗记录。你能帮忙吗?
模型/Customer.cs
public class Customer
{
public int Id { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(50)]
public string Surname { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[StringLength(50)]
public string BusinessCode { get; set; }
}
dtos 文件夹中的文件“GetCustomerDto.cs”
Dtos/Customer/GetCustomerDto.cs
public class GetCustomerDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string BusinessCode { get; set; }
}
模型文件夹内的“Treatment.cs”文件
模型/Treatment.cs
public class Treatment
{
public int Id { get; set; }
[Required]
[StringLength(25)]
public string UserId { get; set; }
[StringLength(100)]
public string ToothNumber { get; set; }
[StringLength(100)]
public string ToothGroup { get; set; }
[DataType(DataType.Text)]
public string Operation { get; set; }
[DataType(DataType.Text)]
public string Action { get; set; }
}
var dbCustomer = await _context.Customers.Where(c => c.UserId == UserId)
.Include(c => c.Treatments)
.FirstOrDefaultAsync(c => c.Id == id);
【问题讨论】:
-
很抱歉,我在您的 Customer 类中看不到 UserId
标签: .net asp.net-core .net-core entity-framework-core entity-relationship