I am getting values from different tables i var type and I want to return them. What should be the return type of the function:-
public void getlist()
{
try
{
using (ShowDataToClientDataContext c = new ShowDataToClientDataContext())
{
var recList = (from record in c.GetTable<T_RECORDSHOW>()
where record.RecordStatus.Equals(RecordStatus.Active)
select new
{
Student = (from stu in c.T_STUDENTSHOWs
where stu.Id.Equals(record.StudentId)
select stu.Name).Single().ToString(),
Trade = (from t in c.T_TRADESHOWs
where t.Id.Equals(record.TradeId)
select t.Name).Single().ToString(),
SessionId = (from s in c.T_SESSIONSHOWs
where s.Id.Equals(record.SessionId)
select s.Name).Single().ToString(),
Month = record.Month.ToString(),
Attendance = record.Attendance.ToString(),
}).ToList();
return recList;
}
}
catch
{
}
}
anybody there to help me?
varisn’t a type in itself. It just asks the compiler to infer the type of the local variable.Now in your case, the type is a
List<T>where theTis an anonymous type. If you want to be able to use the properties within the elements of the list from other code, you’ll need to either do so dynamically (ick) or turn the anonymous type into a full, named type. Anonymous types are really only designed to be used from the methods where the objects are created. You can then return aList<DenormalizedRecord>or whatever.Also note that your query would be much simpler if you’d just use joins: