0

I have a Class see below, when i am trying to query it from another page it not linking e.g. if i put "var Notes = HandhedNotes.GetNotesByLinkIDJoin();" when i look at Notes theres not links there. I think its due to the IQuerable maybe I should be using something elese??

namespace WebSys { public partial class HandheldNote { public static IQueryable GetNotesByLinkIDJoin() { WebSysDataContext db = new WebSysDataContext(Contexts.WEBSYS_CONN()); var Note = from x in db.HandheldNotes join t in db.Employees on x.By equals t.EmployeeNo orderby x.DateAdded select new { DateRaised = x.DateAdded, Note = x.Note, TypeID = x.TypeID, EmployeeID = t.Forenames + " " + t.Surname }; return (IQueryable)Note; } } 

}

2 Answers 2

1

whatever you need.
it appears that you are actually trying to get a collection of notes, so you could do this...

public IList<Note> GetMyNotes() { IList<Note> NoteList = (from x in db.HandheldNotes join t in db.Employees on x.By equals t.EmployeeNo orderby x.DateAdded select new Note { DateRaised = x.DateAdded, Note = x.Note, TypeID = x.TypeID, EmployeeID = t.Forenames + " " + t.Surname }).ToList<Note>(); return NoteList; } 
Sign up to request clarification or add additional context in comments.

Comments

1

you have not enumerated over anything. Lazy loading at it's finest. access one of the anonymous parameters on Note and you will be able to access them all.

what you could also do is create the class...

public class Note { public DateTime DateRaised; public string Note ; public int TypeID; public string EmployeeID; } 

and then

Note Note = (from x in db.HandheldNotes join t in db.Employees on x.By equals t.EmployeeNo orderby x.DateAdded select new Note { DateRaised = x.DateAdded, Note = x.Note, TypeID = x.TypeID, EmployeeID = t.Forenames + " " + t.Surname }).FirstOrDefault(); return Note; 

I think it is important to say this:

you are creating the DataContext and then trying to return a LINQ variable that has not been enumerated on. You will get an error that the underlying datacontext does not exist when you try to access this information. your 2 options are to either have the Datacontext elsewhere or to return an enumerated value from this function. use ToArray() or ToList() or something similar...

Comments