locked
Where have the Gurus gone. Please help an idiot. RRS feed

  • Question

  • User1929428035 posted

    First of all please point me to a good resource for learning LINQ to SQL. All I want to do is have the student's name show in the gridview instead of the ID. This part of a Entity Framework Dynamic Data Project.

    This code returns the student's name:

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


    However I need to retrieve a class of students based on the teacher who is logged in:

    var query = (from sa in this.ObjectContext.StudentAttendances.Include("Student")
        join cs in this.ObjectContext.ClassStudents.Include("Student")
        on sa.StudentID equals cs.StudentID
        join tc in this.ObjectContext.TeacherClasses
        on cs.ClassID equals tc.ClassID
        where cs.ClassID == ClID
        orderby cs.StudentID
        select sa);
    return query;

    Tables in the query:

    1. StudentAttendance: ID, StudentID, Date, Present, Late (Present and Late are boolean)
    2. ClassStudent: ID, ClassID, StudentID
    3. TeacherClass: ID, TeacherID, ClassID

    People have recommended various solutions none of which have worked. Please help before I shoot somebody or myself.

    Tuesday, June 11, 2013 5:09 AM

Answers

  • User1929428035 posted

    I have solved the problem. What I did was to write a function that returned a list of studentids. Used that list in the where clause:

    return this.ObjectContext.StudentAttendances.Include("Student").Where(s => listofstudents.Any(i => i == s.StudentID)).OrderBy(s => s.StudentID);

    Worked perfectly. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 17, 2013 7:10 AM

All replies

  • User-330204900 posted

    Hi mr41971, you don't need to do any Linq queries to get this to happen all you need is to specify the column you want to display using the [DisplayName()] attibute on the table in your metadata, if you want the full name then I use the override of tostring see Riak Anderson's post here Improving the FK field display: Showing two fields in Foreign Key columns it works for me.

    Tuesday, June 11, 2013 11:52 AM
  • User1929428035 posted

    Steve I have tried to implement his override of the ToString function without success:

    [MetadataTypeAttribute(typeof(Student.StudentMetadata))]
    [DisplayName("Students")]
    //[DisplayColumn("FirstName")]
    public partial class Student
    {
         public override string ToString()
         {
    	   return LastName.ToString() + ", " + FirstName.ToString();
         }
    
         internal sealed class StudentMetadata
         {

    I also created a partial class in a separate cs file and it also did not work. Steve this is the last major thing I need to do. Please help I beg you.

     

    Wednesday, June 12, 2013 1:03 AM
  • User-330204900 posted

    if this is not working then I think you may have a namespace issue does any of you metadata work?

    Wednesday, June 12, 2013 8:10 AM
  • User1929428035 posted

    Steve I am a dummy when it comes to DD. So I am not sure how to know if the metadata is working. If the Data Annotations are related to the metadata then that works perfectly. If the [RequiresAuthentication] and [RequiresRole] are related to metadata those also work perfectly.

    Wednesday, June 12, 2013 9:19 AM
  • User-330204900 posted

    what I do to check if my metadata namespace is correct is add a dummy property if the metadata is working correctly you will get an error, however if the namespace is incorrect then you will get no error :)

    Wednesday, June 12, 2013 10:04 AM
  • User1929428035 posted

    Forgive my ignorance. Do you mean: property Early { set; get } or: boolean Early?

    Wednesday, June 12, 2013 10:08 AM
  • User-330204900 posted

    Hi I mean add a property than does not exist into one of your entities i.s. add

    [MetadataTypeAttribute(typeof(Student.StudentMetadata))]
    [DisplayName("Students")]
    [DisplayColumn("FirstName","LastName")]
    public partial class Student
    {
        public override string ToString()
        {
            return LastName.ToString() + ", " + FirstName.ToString();
        }
    
        internal sealed class StudentMetadata
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
    
            // dummy field does not exist in the DB and will
            // generate an error if namespace is correct
            public String Dummy { get; set; }
        }
    }

     

    Thursday, June 13, 2013 8:51 AM
  • User1929428035 posted

    There was no error even after a build. What do I do?

    Thursday, June 13, 2013 9:01 AM
  • User-330204900 posted

    number one that mean you name space and metadata are correct. now if you could post again the offending piece of metadata in the buddy class please.

    Thursday, June 13, 2013 10:46 AM
  • User1929428035 posted

    I think you are refering to this: (The offending piece begins with: "var query"

    [RequiresAuthentication]
    [RequiresRole("Clerk", "Teacher", "Principal", "Parent")]
    public IQueryable<StudentAttendance> GetStudentAttendances()
    {
         SIMSEntities db = new SIMSEntities();
    
         if (this.ServiceContext.User.IsInRole("Parent"))
         {
    	  List<int> intListofStudentIDs = new List<int>();
    	  intListofStudentIDs = getStudentIDsByParent(getTeacherID());
              return this.ObjectContext.StudentAttendances.Include("Student").Where(s =>    intListofStudentIDs.Any(i => i == s.StudentID)).OrderBy(s => s.StudentID);
         }
    
         Int32 ClID = 0;
         ClID = Convert.ToInt32(HttpContext.Current.Session["ClassID"]);
    
         if (this.ServiceContext.User.IsInRole("Teacher"))
         {
               var query = (from sa in this.ObjectContext.StudentAttendances.Include("Student")
               join cs in this.ObjectContext.ClassStudents.Include("Student")
               on sa.StudentID equals cs.StudentID
               join tc in this.ObjectContext.TeacherClasses
               on cs.ClassID equals tc.ClassID
               where cs.ClassID == ClID
               orderby cs.StudentID
               select sa);
               return query;
          }
    			return                         t              this.ObjectContext.StudentAttendances.Include("Student").OrderBy(s => s.Student);
    }
     
    


    I really appreciate your help Steve.

    Thursday, June 13, 2013 11:52 AM
  • User-330204900 posted

    Sorry but this does not seem to be you metadata, not sure what part of your code it is?

    Thursday, June 13, 2013 12:54 PM
  • User1929428035 posted

    There are two file simsDomainService.cs and simsDomainService.metadata.cs Are you referring to the latter if so here it is:

    namespace sims
    {
    	using System;
    	using System.Collections.Generic;
    	using System.ComponentModel;
    	using System.ComponentModel.DataAnnotations;
    	using System.Data.Objects.DataClasses;
    	using System.Linq;
    	using System.ServiceModel.DomainServices.Hosting;
    	using System.ServiceModel.DomainServices.Server;
    
    	// The MetadataTypeAttribute identifies TeacherClassMetadata as the class
    	// that carries additional metadata for the TeacherClass class.
    	[MetadataTypeAttribute(typeof(TeacherClass.TeacherClassMetadata))]
    	[DisplayName("Teacher's Classes")]
    	public partial class TeacherClass
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the TeacherClass class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class TeacherClassMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private TeacherClassMetadata()
    			{
    			}
    
    			public Class Class { get; set; }
    
    			public long ClassID { get; set; }
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Teacher Teacher { get; set; }
    
    			public long TeacherID { get; set; }
    		}
    	}
    	[MetadataTypeAttribute(typeof(Class.ClassMetadata))]
    	[DisplayName("Classes")]
    	[ScaffoldTable(false)]
    	[HideTableInDefault(true)]
    	public partial class Class
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the Class class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    
    
    		internal sealed class ClassMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    
    			private ClassMetadata()
    			{
    			}
    
    			[DisplayName("Class")]
    			public string ClassName { get; set; }
    
    			public EntityCollection<ClassStudent> ClassStudents { get; set; }
    
    			public EntityCollection<HomeWork> HomeWork { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Teacher Teacher { get; set; }
    
    			public Nullable<long> TeacherID { get; set; }
    
    
    		}
    	}
    
    	// The MetadataTypeAttribute identifies ClassStudentMetadata as the class
    	// that carries additional metadata for the ClassStudent class.
    	[MetadataTypeAttribute(typeof(ClassStudent.ClassStudentMetadata))]
    	[DisplayName("Classes")]
    	public partial class ClassStudent
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the ClassStudent class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class ClassStudentMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private ClassStudentMetadata()
    			{
    			}
    
    			[DisplayName("Academic Year")]
    			public string AcademicYear { get; set; }
    
    			public Class Class { get; set; }
    
    			public long ClassID { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies HomeWorkMetadata as the class
    	// that carries additional metadata for the HomeWork class.
    	[MetadataTypeAttribute(typeof(HomeWork.HomeWorkMetadata))]
    	[DisplayName("Home Work")]
    	public partial class HomeWork
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the HomeWork class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class HomeWorkMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private HomeWorkMetadata()
    			{
    			}
    
    			public Class Class { get; set; }
    
    			public long ClassID { get; set; }
    
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			[DisplayName("Given Date")]
    			public DateTime DateHWGiven { get; set; }
    
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			[DisplayName("Due Date")]
    			public DateTime DueDate { get; set; }
    
    			[DisplayName("Details")]
    			public string HomeWorkDetails { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Subject Subject { get; set; }
    
    			public long SubjectID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies NoticeMetadata as the class
    	// that carries additional metadata for the Notice class.
    	[MetadataTypeAttribute(typeof(Notice.NoticeMetadata))]
    	[DisplayName("Notices")]
    	public partial class Notice
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the Notice class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class NoticeMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private NoticeMetadata()
    			{
    			}
    
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			public DateTime Date { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			[DisplayName("Notice")]
    			public string Notice1 { get; set; }
    
    			[DisplayName("Title")]
    			public string NoticeTitle { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies ParentGuardianMetadata as the class
    	// that carries additional metadata for the ParentGuardian class.
    	[MetadataTypeAttribute(typeof(ParentGuardian.ParentGuardianMetadata))]
    	[DisplayName("Parents/Guardians")]
    	public partial class ParentGuardian
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the ParentGuardian class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class ParentGuardianMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private ParentGuardianMetadata()
    			{
    			}
    
    			[DisplayName("Area/Town")]
    			public string AreaTown { get; set; }
    
    			[DisplayName("Cell Phone No.")]
    			public string CellPhone { get; set; }
    
    			public string City { get; set; }
    
    			public string Country { get; set; }
    
    			public string Email { get; set; }
    
    			[DisplayName("First Name")]
    			public string FirstName { get; set; }
    
    			[DisplayName("Home Phone No.")]
    			public string HomePhone { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			[DisplayName("Last Name")]
    			public string LastName { get; set; }
    
    			public EntityCollection<ParentStudent> ParentStudents { get; set; }
    
    			public string Photo { get; set; }
    
    			[DisplayName("Relation to Student")]
    			public string RelationToStudent { get; set; }
    
    			public string Street { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies ParentStudentMetadata as the class
    	// that carries additional metadata for the ParentStudent class.
    	[MetadataTypeAttribute(typeof(ParentStudent.ParentStudentMetadata))]
    	[DisplayName("Student's Parents/Guardians")]
    	public partial class ParentStudent
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the ParentStudent class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class ParentStudentMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private ParentStudentMetadata()
    			{
    			}
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public ParentGuardian ParentGuardian { get; set; }
    
    			public long ParentID { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies SchoolMetadata as the class
    	// that carries additional metadata for the School class.
    	[MetadataTypeAttribute(typeof(School.SchoolMetadata))]
    	public partial class School
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the School class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class SchoolMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private SchoolMetadata()
    			{
    			}
    
    			[DisplayName("Area/Town")]
    			public string AreaTown { get; set; }
    
    			public string City { get; set; }
    
    			public string Country { get; set; }
    
    			public string Email { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public string Name { get; set; }
    
    			public string Phone { get; set; }
    
    			public string Street { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentMetadata as the class
    	// that carries additional metadata for the Student class.
    	[MetadataTypeAttribute(typeof(Student.StudentMetadata))]
    	[DisplayName("Students")]
    	[DisplayColumn("FirstName", "LastName")]
    	public partial class Student
    	{
    		public override string ToString()
    		{
    			return LastName.ToString() + ", " + FirstName.ToString();
    		}
    
    		internal sealed class StudentMetadata
    		{
    			public string fummmy { get; set; }
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentMetadata()
    			{
    			}
    
    			[DisplayName("Area/Town")]
    			public string AreaTown { get; set; }
    
    			[DisplayName("Cell Phone No.")]
    			public string CellPhone { get; set; }
    
    			public string City { get; set; }
    
    			public EntityCollection<ClassStudent> ClassStudents { get; set; }
    
    			public string Country { get; set; }
    
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			[DisplayName("Date of Birth")]
    			public Nullable<DateTime> DateofBirth { get; set; }
    
    			public string Email { get; set; }
    
    			[DisplayName("First Name")]
    			public string FirstName { get; set; }
    
    			public string Gender { get; set; }
    
    			[DisplayName("Home Phone No.")]
    			public string HomePhone { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			[DisplayName("Last Name")]
    			public string LastName { get; set; }
    
    			public EntityCollection<ParentStudent> ParentStudents { get; set; }
    
    			public byte[] Photo { get; set; }
    
    			public Nullable<long> StatusID { get; set; }
    
    			public string Street { get; set; }
    
    			public EntityCollection<StudentAttendance> StudentAttendances { get; set; }
    
    			public EntityCollection<StudentDisciplinaryRecord> StudentDisciplinaryRecords { get; set; }
    
    			public EntityCollection<StudentEarlyDeparture> StudentEarlyDepartures { get; set; }
    
    			public EntityCollection<StudentMedicalRecord> StudentMedicalRecords { get; set; }
    
    			public EntityCollection<StudentPerformance> StudentPerformances { get; set; }
    
    			public StudentStatu StudentStatu { get; set; }
    
    			public EntityCollection<StudentSubject> StudentSubjects { get; set; }
    		}
    	}
    	
    
    	// The MetadataTypeAttribute identifies StudentAttendanceMetadata as the class
    	// that carries additional metadata for the StudentAttendance class.
    	[MetadataTypeAttribute(typeof(StudentAttendance.StudentAttendanceMetadata))]
    	[DisplayName("Student Attendance Register")]
    	public partial class StudentAttendance
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentAttendance class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentAttendanceMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentAttendanceMetadata()
    			{
    			}
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			public DateTime Date { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public bool Late { get; set; }
    
    			public bool Present { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentDisciplinaryRecordMetadata as the class
    	// that carries additional metadata for the StudentDisciplinaryRecord class.
    	[MetadataTypeAttribute(typeof(StudentDisciplinaryRecord.StudentDisciplinaryRecordMetadata))]
    	[DisplayName("Student Disciplinary Records")]
    	public partial class StudentDisciplinaryRecord
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentDisciplinaryRecord class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentDisciplinaryRecordMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentDisciplinaryRecordMetadata()
    			{
    			}
    			//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			[DisplayName("Date and Time of Notification")]
    			public Nullable<DateTime> DateTimeofNotification { get; set; }
    
    			[DisplayName("Incident Descrption")]
    			public string DescriptionofIncident { get; set; }
    
    			[DisplayName("Disciplinary Action Taken")]
    			public string DisciplinaryActionTaken { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			[DisplayName("Date of Incident")]
    			public DateTime IncidentDate { get; set; }
    
    			[DisplayName("Name of Person Notified")]
    			public string NameofPersonNotified { get; set; }
    
    			[DisplayName("Was Notification Given")]
    			public Nullable<bool> ParentGuardianNotified { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentEarlyDepartureMetadata as the class
    	// that carries additional metadata for the StudentEarlyDeparture class.
    	[MetadataTypeAttribute(typeof(StudentEarlyDeparture.StudentEarlyDepartureMetadata))]
    	[DisplayName("Student Early Departures")]
    	public partial class StudentEarlyDeparture
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentEarlyDeparture class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentEarlyDepartureMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentEarlyDepartureMetadata()
    			{
    			}
    
    			[DisplayName("Authorized By")]
    			public string AuthorizedBy { get; set; }
    
    			public Nullable<DateTime> DateTime { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			[DisplayName("Name of person who requested Early Departure")]
    			public string PersonWhoRequestedEarlyDeparture { get; set; }
    
    			[DisplayName("Reason for Early Departure")]
    			public string ReasonforEarlyDeparture { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentMedicalRecordMetadata as the class
    	// that carries additional metadata for the StudentMedicalRecord class.
    	[MetadataTypeAttribute(typeof(StudentMedicalRecord.StudentMedicalRecordMetadata))]
    	[DisplayName("Student Medical Records")]
    	public partial class StudentMedicalRecord
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentMedicalRecord class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentMedicalRecordMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentMedicalRecordMetadata()
    			{
    			}
    
    			public string Dosage { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public string Illness { get; set; }
    
    			public string Medication { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentPerformanceMetadata as the class
    	// that carries additional metadata for the StudentPerformance class.
    	[MetadataTypeAttribute(typeof(StudentPerformance.StudentPerformanceMetadata))]
    	[DisplayName("Student Grades")]
    	public partial class StudentPerformance
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentPerformance class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentPerformanceMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentPerformanceMetadata()
    			{
    			}
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			public DateTime Date { get; set; }
    
    			public string Grade { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Nullable<decimal> Result { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    
    			public Subject Subject { get; set; }
    
    			public long SubjectID { get; set; }
    
    
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentStatuMetadata as the class
    	// that carries additional metadata for the StudentStatu class.
    	[MetadataTypeAttribute(typeof(StudentStatu.StudentStatuMetadata))]
    	[DisplayName("Student Status Lookup")]
    	[HideTableInDefault(true)]
    	public partial class StudentStatu
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentStatu class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentStatuMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentStatuMetadata()
    			{
    			}
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public string Status { get; set; }
    
    			public EntityCollection<Student> Students { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies StudentSubjectMetadata as the class
    	// that carries additional metadata for the StudentSubject class.
    	[MetadataTypeAttribute(typeof(StudentSubject.StudentSubjectMetadata))]
    	[DisplayName("Student's Subjects")]
    	[HideTableInDefault(true)]
    	public partial class StudentSubject
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentSubject class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentSubjectMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentSubjectMetadata()
    			{
    			}
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    
    			public Subject Subject { get; set; }
    
    			public long SubjectID { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies SubjectMetadata as the class
    	// that carries additional metadata for the Subject class.
    	[MetadataTypeAttribute(typeof(Subject.SubjectMetadata))]
    	[DisplayName("Subjects")]
    	[ScaffoldTable(false)]
    	[HideTableInDefault(true)]
    	public partial class Subject
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the Subject class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class SubjectMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private SubjectMetadata()
    			{
    			}
    
    			public EntityCollection<HomeWork> HomeWork { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public EntityCollection<StudentPerformance> StudentPerformances { get; set; }
    
    			public EntityCollection<StudentSubject> StudentSubjects { get; set; }
    
    			[DisplayName("Subject")]
    			public string Subject1 { get; set; }
    
    			public EntityCollection<TeacherSubject> TeacherSubjects { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies TeacherMetadata as the class
    	// that carries additional metadata for the Teacher class.
    	[MetadataTypeAttribute(typeof(Teacher.TeacherMetadata))]
    	[DisplayName("Teachers")]
    	public partial class Teacher
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the Teacher class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class TeacherMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private TeacherMetadata()
    			{
    			}
    
    			[DisplayName("Area/Town")]
    			public string AreaTown { get; set; }
    
    			[DisplayName("Cell Phone")]
    			public string CellPhone { get; set; }
    
    			public string City { get; set; }
    
    			public EntityCollection<Class> Classes { get; set; }
    
    			public string Country { get; set; }
    
    			public string Email { get; set; }
    
    			[DisplayName("First Name")]
    			public string FirstName { get; set; }
    
    			[DisplayName("Home Phone No.")]
    			public string HomePhone { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			[DisplayName("Last Name")]
    			public string LastName { get; set; }
    
    			public string Street { get; set; }
    
    			public EntityCollection<TeacherSubject> TeacherSubjects { get; set; }
    		}
    	}
    
    	// The MetadataTypeAttribute identifies TeacherSubjectMetadata as the class
    	// that carries additional metadata for the TeacherSubject class.
    	[MetadataTypeAttribute(typeof(TeacherSubject.TeacherSubjectMetadata))]
    	[DisplayName("Subjects Taught by Teachers")]
    	public partial class TeacherSubject
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the TeacherSubject class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class TeacherSubjectMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    
    			private TeacherSubjectMetadata()
    			{
    			}
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public Subject Subject { get; set; }
    
    			public long SubjectID { get; set; }
    
    			public Teacher Teacher { get; set; }
    
    			public long TeacherID { get; set; }
    		}
    	}
    }
    



    Thursday, June 13, 2013 1:01 PM
  • User1929428035 posted

    I have extracted the relevant code for you to focus on:

    [MetadataTypeAttribute(typeof(StudentAttendance.StudentAttendanceMetadata))]
    	[DisplayName("Student Attendance Register")]
    	public partial class StudentAttendance
    	{
    
    		// This class allows you to attach custom attributes to properties
    		// of the StudentAttendance class.
    		//
    		// For example, the following marks the Xyz property as a
    		// required property and specifies the format for valid values:
    		//    [Required]
    		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
    		//    [StringLength(32)]
    		//    public string Xyz { get; set; }
    		internal sealed class StudentAttendanceMetadata
    		{
    
    			// Metadata classes are not meant to be instantiated.
    			private StudentAttendanceMetadata()
    			{
    			}
    			[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    			public DateTime Date { get; set; }
    
    			[ScaffoldColumn(false)]
    			public long ID { get; set; }
    
    			public bool Late { get; set; }
    
    			public bool Present { get; set; }
    
    			public Student Student { get; set; }
    
    			public long StudentID { get; set; }
    		}
    	}
    



    Friday, June 14, 2013 1:12 AM
  • User-330204900 posted

    Hi there this is what you would do:

    [MetadataTypeAttribute(typeof(StudentAttendance.StudentAttendanceMetadata))]
    // remove because you dont have a field in the table
    //[DisplayName("Student Attendance Register")]
    public partial class StudentAttendance
    {
        public override string ToString()
        {
            return Student.LastName.ToString() + ", " + Student.FirstName.ToString();
        }
    
        internal sealed class StudentAttendanceMetadata
        {
            [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
            public DateTime Date { get; set; }
    
            [ScaffoldColumn(false)]
            public long ID { get; set; }
    
            public bool Late { get; set; }
    
            public bool Present { get; set; }
    
            public Student Student { get; set; }
    
            public long StudentID { get; set; }
        }
    }

    plus have you had any milage with the custom fields you have in the Students table as I did not think they were supported.

    Friday, June 14, 2013 6:40 AM
  • User1929428035 posted

    It still did not work the foreinkey value for studentid is still being displayed.

    Friday, June 14, 2013 6:47 AM
  • User-330204900 posted

    Sorry My Bad I was thinking of DisplayColumn :(

    Friday, June 14, 2013 6:57 AM
  • User1929428035 posted

    I did not notice this line:

    public Student Student { get; set; }

    However when I added it and ran the project I got this error:

    Error 1 The type 'sims.StudentAttendance.StudentAttendanceMetadata' already contains a definition for 'Student' 



    Friday, June 14, 2013 7:33 AM
  • User1929428035 posted

    I copied and pasted your code did not get any errors but the result was the same.

    Friday, June 14, 2013 7:36 AM
  • User1929428035 posted

    I have solved the problem. What I did was to write a function that returned a list of studentids. Used that list in the where clause:

    return this.ObjectContext.StudentAttendances.Include("Student").Where(s => listofstudents.Any(i => i == s.StudentID)).OrderBy(s => s.StudentID);

    Worked perfectly. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 17, 2013 7:10 AM