locked
Filter Problem RRS feed

  • Question

  • User1929428035 posted

    In my Dynamic Data Entity Framework project I have the following entities:

    Student: ID, FirstName, LastName
    Class: ID, ClassName
    Teacher: ID, FirstName, LastName

    They have the following relationships:

    A Student can be in one or more Classes
    A Class can have one or more Students
    A Teacher may teach one or more Classes
    A Class may be taught by one or more Teachers

    The relations are represented by the following Join tables:

    ClassStudent: ID, ClassID, StudentID, AcademicYear
    TeacherClass: ID, TeacherID, ClassID

    The problem: I would like that when a Teacher logs in to update the StudentAttendanceRegister the Class filter must have only the classes she teaches and the list of students must belong to the selected class.

    StudentAttendanceRegister: ID, Date, StudentID, Present

    Please help been at this for about a month.

    Tuesday, May 28, 2013 2:21 AM

Answers

  • User-330204900 posted

    OK so the Linq code would be something like this 

    return this.ObjectContext.StudentAttendance.Where(s => s. ClassStudent. TeacherClass.TeacherId == TeacherId);

    that may not be exactly what you would do but without the actual model (and the help of intelisense) I can’t more exact.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 1, 2013 7:08 AM

All replies

  • User-168800120 posted
    Create PROC StudentAttendanceRegister
    (
    @TeacherId INT
    ) 
    As 
    BEGIN
    
    SELECT S.StudentName, C.ClassName
    FROM Student AS S 
    JOIN Class AS C On C.ClassId = S.ClassId
    JOIN Teacher AS T ON T.ClassId = C.ClassId
     Where T.TeacherId = @TeacherId 
    
     END

    I have written sproc for above requirement. You can use that and call that sproc in Entity framework.

    Tuesday, May 28, 2013 9:04 AM
  • User1929428035 posted

    Thank you very much. I am relatively new to Dynamic Data so please explain how would I use your suggestion to return an ObjectContext e.g.:

    return this.ObjectContext.StudentAttendances.Include("Student").OrderBy(s => s.ID);


    Tuesday, May 28, 2013 4:45 PM
  • User-330204900 posted

    Hi Martin I just reply to your e-mail :) the easiest way to do this would be to use Domain Service (this has some drawbacks such as no support for Many to Many relationships) however I normally create a special custom filter and populate it myself this big issue here is that you need to supply a list of all Id’s for the ALL filter entry.

    Wednesday, May 29, 2013 10:33 AM
  • User350138131 posted
    CREATE VIEW [dbo].[TeachersStudents]
    AS
    SELECT     T.teacherId, TC.classId, S.studentId, S.studentFirstName, S.studentLastName,
     C.className, CS.classstudentAcademicYear, T.teacherFirstName, 
                          T.teacherLastName
    FROM         dbo.Teachers AS T INNER JOIN
                          dbo.TeachersClasses AS TC ON T.teacherId = TC.teacherId LEFT OUTER JOIN
                          dbo.ClassesStudents AS CS ON TC.classId = CS.classId LEFT OUTER JOIN
                          dbo.Classes AS C ON TC.classId = C.classId LEFT OUTER JOIN
                          dbo.Students AS S ON CS.studentId = S.studentId

    TeachersClasses -> TeachersStudents by teacherId and classId

        [MetadataType(typeof(TeachersStudents_MD))]
        public partial class TeachersStudents
        {
            public class TeachersStudents_MD
            {
                [FilterUIHint("Cascade")]
                [nacDA.Cascade("Teachers")]
                public object TeachersClasses { get; set; }
            }
        }
    
        [MetadataType(typeof(TeachersClasses_MD))]
        public partial class TeachersClasses
        {
            public string classCall
            {
                get
                {
                    return this.Classes.className;
                }
            }
            [DisplayColumn("classCall")]
            public class TeachersClasses_MD
            {
            }
        }

    If I understand correctly.

    Friday, May 31, 2013 5:31 AM
  • User-330204900 posted

    Are you using a DomainService in your DD application?

    Friday, May 31, 2013 5:56 AM
  • User1929428035 posted

    Yes I am steve.

    Friday, May 31, 2013 3:49 PM
  • User-330204900 posted

    OK so the Linq code would be something like this 

    return this.ObjectContext.StudentAttendance.Where(s => s. ClassStudent. TeacherClass.TeacherId == TeacherId);

    that may not be exactly what you would do but without the actual model (and the help of intelisense) I can’t more exact.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 1, 2013 7:08 AM