5 framework, without using a foreign key relationship in the database, and I wonder how 4.0 can improve this garbage code that I need to pass back through several objects after several table joins.
public IList<User> GetTutorByCourseId(int courseId)
{
IList<User> output = new List<User>();
using (leDataContext db = new leDataContext())
{
try
{
var m = from c in db.Courses
join ct in db.CourseByTutors on c.Id equals ct.CourseId
join u in db.Users on ct.TutorId equals u.Id
where c.Id == courseId
select new
{
c, ct, u
};
foreach (var result in m)
{
User user = new User();
user.Id = result.u.Id;
user.Name = result.u.Name;
user.CourseTutor.Id = result.ct.Id;
user.Course.Name = result.c.Name;
output.Add(user);
}
return output;
}
catch (Exception ex)
{
Logger.Error(typeof(User), ex.ToString());
throw;
}
}
}
3 objects are returned in the GUI. However, for this I need to add the property Public CourseByTutors {get; set} and the public course (get; set;) in the User class, which I found to ruin my code. In this case, how could 4.0 solve this? I read something about choosing tupel .. ??
source
share