asp.net - 如何在使用 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; }
}
我正在使用通用存储库模式。我无法通过子服务表从服务表中检索数据。如何检索服务表的数据
解决方案
假设您正确设置了 mongodb,您必须调用.Include(x => x.Service)
DbSet
推荐阅读
- magento - 从数据库中的跟踪号中删除空格
- string - 从文件读取时将空字符串更改为“Nostring”
- xamarin.forms - 如何实现一个本机图像查看器,用捏来放大 Xamarin.Forms?
- android - Android资源未找到异常oncreate
- java - Android - 使用时区转换当前日期和时间
- php - 如何根据当前登录android的用户检索数据
- laravel - 更新 Laravel Illuminate 集合中的单个键值
- selenium - Selenium:PhantomJS:网站呈现为移动网站
- qt - 向模拟时钟添加滴答声
- mysql - 从 VM 实例访问远程 MySQL 数据库