在实体框架中加载选定的基元属性
我在 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 技术交流群。

不适用于负载属性,不适用于实体。您必须创建自定义查询并使用投影来仅加载选定的列:
Not with load property and not with entities. You must create custom query and use projection to load only selected columns: