在实体框架中加载选定的基元属性

发布于 12-01 14:35 字数 761 浏览 5 评论 0原文

我在 Oracle 数据库中有以下结构:

Course(CourseId, Name)
->Student(StudentId, Name, Comment, CourseId)
->Subject(SubjectId, Name, SubjectComment, CourseId)

Student 包含一些原始属性 (StudentId、Name、CourseId、Comment) 和导航属性 (课程 [与 CourseId 上的 DTO 名称课程链接]).

表结构也与实体结构相同,目前使用显式加载从 Oracle 数据库中提取数据,使用 LoadProperty 和 Load。

我需要使用选定的属性加载集合和对象,如使用 StudentId 和 Name 加载学生(没有注释列)。

LoadProperty(Student, s => s.Courses),仅加载 CourseId(不加载 Course DTO 中的 Name 原始属性)。因此,Student.Courses.First().CourseId 将是一个值,Name 将为 null,因为有意从数据库加载中排除。

LoadProperty(Course, c => c.Subjects) 只加载SubjectId,不加载Name属性,甚至不去数据库加载。

有什么方法可以包含/排除要加载的基元类型吗?

I have following structure in Oracle database:

Course(CourseId, Name)
->Student(StudentId, Name, Comment, CourseId)
->Subject(SubjectId, Name, SubjectComment, CourseId)

Student contains some of Primitive Properties (StudentId, Name, CourseId, Comment) and Navigation Property (Courses [Linked with DTO name Course on CourseId]).

Table structure is also same as Entity structure and currenly using Explicit loading to extract the data from Oracle database, using LoadProperty and Load.

I need to load the Collection and Object with selected property, as Load Student with StudentId and Name (without Comment column).

LoadProperty(Student, s => s.Courses), load only CourseId (don't load Name primitive property in Course DTO). So, Student.Courses.First().CourseId will be a value and Name will be null as intentionally excluded from loading from database.

LoadProperty(Course, c => c.Subjects) load only SubjectId without Name property, even don't go to database to load.

Is there any way to Include/Exclude the Primitive types to load?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫2024-12-08 14:35:46

不适用于负载属性,不适用于实体。您必须创建自定义查询并使用投影来仅加载选定的列:

var student = from s in context.Students
              select new {
                      StudentId = s.StudentId,
                      ... // Other student's properties
                      CourseId = s.Course.Id,
                      SubjectIds = s.Courese.Subjects.Select(s => s.Ids)   
                  };

Not with load property and not with entities. You must create custom query and use projection to load only selected columns:

var student = from s in context.Students
              select new {
                      StudentId = s.StudentId,
                      ... // Other student's properties
                      CourseId = s.Course.Id,
                      SubjectIds = s.Courese.Subjects.Select(s => s.Ids)   
                  };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文