troubleshooting Question

Linq-to-SQL Syntax Question

Avatar of adskarcox
adskarcoxFlag for United States of America asked on
.NET ProgrammingC#ASP.NET
5 Comments3 Solutions460 ViewsLast Modified:
Hello,

My questions concern this Linq-to-SQL statement:

var r in db.Roles.OrderBy(c => c.RoleName)

1) What is the syntax form called where dots are used in Linq, instead of just typing out a full Linq statement (hopefully this makes sense).

2) I understand what "c => c.RoleName" does, but I do not understand why the syntax is organized like that.  I feel that this would make more sense:

var r in db.Roles.OrderBy(r.RoleName)

or this:

var r in db.Roles.OrderBy(RoleName)

Why is this needed: "c => c.RoleName"?  I don't understand the purpose of pointing c to c.RoleName.  This is not as intuitive as the two examples I provided above and at this point I do not have a complete understanding of why the syntax is arranged like it is.

Any assistance with these two questions would be greatly appreciated.  Long answers are welcome :)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros