首页 > 解决方案 > 如何在使用 asp.net core 和 mongodb 时从一对多关系表中获取数据

问题描述

我有两个表服务和子服务:

 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; }
}

我正在使用通用存储库模式。我无法通过子服务表从服务表中检索数据。如何检索服务表的数据

标签: asp.netmongodbasp.net-coreasp.net-core-2.0

解决方案


假设您正确设置了 mongodb,您必须调用.Include(x => x.Service)DbSet


推荐阅读