Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRadu - Adrian Buha
Courses Plus Student 5,535 PointsHow can I display the result of the queries from this video inside a console app in Visual Studio?
Hello,
Because the REPL is a bit unreliable for this section of C# and because I wanted to learn better these queries, I want to implement these queries in Console Application in Visual Studio.
Therefore, my question is, how can I display these queries results in the Console Window?
Thank you!
6 Answers
Steven Parker
231,268 PointsI got your request.
I'm used to using Entity Framework where you deal with the database in a way where results come back in an object which has properties that represent the various columns returned by the query.. There are several courses here covering the use of EF.
But you can also make queries using a more fundamental mechanism involving a Command Object. Then you can retrieve the results with an Execution Reader or Table Adapter. See this MSDN page on How to Create and Execute an SQL Statement that Returns Rows.
Cati lucian
10,119 Pointshttps://docs.microsoft.com/es-es/aspnet/core/data/ef-mvc/ Is a good page to look!
Radu - Adrian Buha
Courses Plus Student 5,535 PointsYour link is in Spanish.
Radu - Adrian Buha
Courses Plus Student 5,535 PointsAll I want is to print to Console Window this query:
var groupedBirds = birds.GroupBy(b => b.Color);
But if I try to print it with the foreach loop I get this result:
System.Linq.Lookup'2+Grouping[System.String,Aggregates.Bird] System.Linq.Lookup'2+Grouping[System.String,Aggregates.Bird] System.Linq.Lookup'2+Grouping[System.String,Aggregates.Bird] System.Linq.Lookup'2+Grouping[System.String,Aggregates.Bird] System.Linq.Lookup'2+Grouping[System.String,Aggregates.Bird]
I want to get the same result (or at least similar) in the Console Window as Carling gets in the Aggregates tutorial in REPL.
Any ideeas?
Thanks in advance.
Cati lucian
10,119 PointsHi Radu !!! Version English --> https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/ Cheers!
Radu - Adrian Buha
Courses Plus Student 5,535 PointsThank for the link. I will look into it.
Radu - Adrian Buha
Courses Plus Student 5,535 PointsFound my solution. I just needed two foreach, one inside the other:
foreach (var g in groupedBirds) { Console.WriteLine(g.Key); foreach (var ge in g) { Console.WriteLine(ge); }
}
Steven Parker
231,268 PointsThis doesn't seem related to the original question, am I missing something?
Radu - Adrian Buha
Courses Plus Student 5,535 PointsMy question was related on the Aggregates tutorial from Linq Queries. I wanted to display the results for those specific queries from the Aggregates tutorial. I apologize if my original question seemed ambiguous, but English is not my first language. Many thanks for your replies.