首页 > 解决方案 > EF Core 嵌套实体处理

问题描述

我有带有 EF Core 的 .NET Core 应用程序。

我需要获取 Thread 对象的列表,但我还需要嵌套表中的一个属性,它是dbo.Container.Description

我愿意:

var threads = this.context.Threads
                .Include(x => x.ThreadsPosts)
                .ThenInclude(x => x.Post)
                .ThenInclude(x => x.CreatedByUser)
                .ThenInclude(x => x.UserProfile)
                .ThenInclude(x => x.Container);

然后我通过线程循环:

var description = thread.ThreadsPosts.Last().Post.CreatedByUser.UserProfile.Container.Description;

但据我了解,我从所有嵌套表的所有列中获取数据?

那么有没有性能问题呢?

也许有一种方法可以减少列数?

如何正确编写此结构?

标签: .net-coreentity-framework-core

解决方案


推荐阅读