Quote:
|
the object r referes to is the myEntities.Reviews object, correct? So, this kind of works like aliasing a table in SQL?
|
Nope, not correct. It doesn't refer to the entire collection, but to a single object. As such it's not an alias to the Reviews collection. Think of it as the iteration variable in a for loop. Within the loop you can access the details of the iteration variable.
The same is true for a LINQ query: you use the r in this case to select the item, but also to filter (e.g. Where r.SomeProperty = SomeValue)
Quote:
|
To make sure I understand: When you "select r" you are just selecting all of the reviews?
|
In this example, yes:
Code:
var allReviews = from r in myEntities.Reviews
select r;
However, with a filter the queries looks like this:
Code:
var allReviews = from r in myEntities.Reviews
where r.Id > 10
select r;
And now it no longer returns all Reviews. r.Id is used here to specify the Where criteria.
Quote:
|
Did they just have the syntax build that way so that you don't have to type myEntities.Reviews in the WHERE statement when you filter? (So, it is like an alias once again?)
|
I don't think so. myEntities.Reviews is a collection, so it wouldn't make sense (nor compile) to do something like:
Where myEntities.Reviews.Id > 10
That would give the Reviews collection itself an Id. With the range varaible, you refer to the objects in the collection which in turn can have an Id.
You should ask Microsoft; they hardcoded it to be it ;-)
Quote:
Similar to my question above, why can't the code be:
Where = "PhotoAlbum.Id = @photoAlbumId" ?
|
Again, it needs to know what object to retrieve that infomation from. The "magic" it variable gives access to that....
Cheers,
Imar