c# - Select LINQ 中的 LINQ - 会有性能问题吗?
问题描述
我想从数据库中查询人员列表,在表中,它有一列还包含亲属列表,这是数据库中的另一个表。这行代码能解决问题吗?它会在未来产生数千个数据的性能问题吗?
参考下面的代码:
public class Employee
{
public int Id { get; set; }
public string Name{ get; set; }
public virtual List<Relatives> { get; set; }
}
public class Relatives
{
public int Id { get; set; }
public string Name{ get; set; }
public int EmployeeId { get; set; }
[ForeignKey("EmployeeId")]
public virtual Employee Employee { get; set; }
}
var list = GetDbSet<Employee>().Select(x => new
{
id = x.Id,
name = x.Name,
ListOfRelatives = string.Join(",", (x.Relatives.Where(y => y.EmployeeId == x.Id).Select(z => z.Name)))
}.ToList();
如果这不是最好的解决方案,还有其他方法可以解决这个问题吗?
解决方案
推荐阅读
- python - 自定义功能不会占用我字典中的所有项目
- vba - 在 AutoNew 子中附加模板的问题
- javascript - AWS Lambda 节点处理问题
- android - 离子/角度引导两次,在 debug.apk 中有效,但在发布时无效
- apache-spark - 如何读取 spark sql 查询执行计划并将其保存到文本文件中?
- angular - 传递数据以形成控制角度
- dart - 如何检查对象是否包含飞镖中的属性
- vue.js - 每次从组件调用时,Vuex 操作都不会更新状态
- php - 我收到 Laravel Mysql 连接错误
- python - requests-html:按内容查找 td