3 ms·
Thanks for continuing to indulge me in this conversation. So, if I understand you correctly, your data looks something like this: StudentId| Name |Cour
by 16bytes 10y ago
Thanks for continuing to indulge me in this conversation. So, if I understand you correctly, your data looks something like this:
StudentId| Name |CourseId
============================
1| Bob| 1
2| Jane| 1
1| Bob| 2
1| Bob| 3
2| Jane| 4
With many more columns of course. The point being that it's a denormalized listing of student-course pairs. If so, you'd be able to get immutability by reading the query result into a data table and doing something like:
var result = from row in dt.AsEnumerable()
group row by row.Field<int>("StudentId") into grp
select new Student(
grp.Key,
grp.First().Field<string>("Name"),
from courseRow in grp select new Course(courseRow)
);
This seems to satisfy all of the conditions that you list (namely immutable objects), but with the added advantages of not needing a inner Completion class, and a number of less lines of code.
Furthermore this is less coupled because now the Student class doesn't need to worry about DataReaders or DataTables or which column names to read from.
I would also argue that this version is a lot easier to read and reason about.
I think you could make a similar transformation for any circumstance in which you wanted to use an out variable in the fashion you outline.
Does that make sense? Is there another case in which you would advocate for our variables in new code?