如何在使用 asp.net 核心和 mongodb 时从一对多关系 table 获取数据
How to get data from one-to-many relationship table while working with asp.net core and mongodb
我有两个 tables 服务和子服务:
public class Service
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
public string ServiceName { get; set; }
public string Description { get; set; }
}
Public class subservice{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
public string SubServiceName { get; set; }
public string Description { get; set; }
public Service Service { get; set; }
public string ServiceId { get; set; }
}
我正在使用通用存储库模式。我无法通过子服务从服务 table 检索数据 table.How 我可以检索服务 table
的数据吗
假设您 mongodb 设置正确,您必须在 DbSet
上调用 .Include(x => x.Service)
我有两个 tables 服务和子服务:
public class Service
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
public string ServiceName { get; set; }
public string Description { get; set; }
}
Public class subservice{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
public string SubServiceName { get; set; }
public string Description { get; set; }
public Service Service { get; set; }
public string ServiceId { get; set; }
}
我正在使用通用存储库模式。我无法通过子服务从服务 table 检索数据 table.How 我可以检索服务 table
的数据吗假设您 mongodb 设置正确,您必须在 DbSet
上调用.Include(x => x.Service)