开发者

Load Selected Primitive Properties in Entity Framework

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 Explic开发者_如何学Cit 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?


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)   
                  };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜