D
d-42
Hi,
I'm trying to under stand linq syntax, and how it relates to 'plain
csharp':
For example, this trivial example grabs the accounts with a name
greater than or equal to "S"...
List<Account> Accounts;
List<Account> mylist = from acc in Accounts where acc.Name >= "S"
select acc.ToList() ;
and it is the same as:
List<Accounts> mylist = Accounts.Where(acc=>acc.Name >="S") .ToList();
But I'm having trouble understanding how to 'translate' more complex
expressions like:
var q = from acc in Accounts
join loc in Locations on acc.AccountID equals loc.AccountID
where loc.IsPrimaryLocation == true
orderby loc.Province descending
select acc;
(Basically the above does an on the fly join with another table,
filters it, and then sorts it by a field in the second table,
ultimately returning the accounts sorted.)
I'd like to translate it out of linq syntax to plain old c#, but I've
gotten over my head; the join in particular is really throwing me. If
someone could translate it I'm hoping I'd be able to see the 'pattern'
that it takes. I'd also appreciate being pointed at any resources that
go over this...
Thanks,
Dave
I'm trying to under stand linq syntax, and how it relates to 'plain
csharp':
For example, this trivial example grabs the accounts with a name
greater than or equal to "S"...
List<Account> Accounts;
List<Account> mylist = from acc in Accounts where acc.Name >= "S"
select acc.ToList() ;
and it is the same as:
List<Accounts> mylist = Accounts.Where(acc=>acc.Name >="S") .ToList();
But I'm having trouble understanding how to 'translate' more complex
expressions like:
var q = from acc in Accounts
join loc in Locations on acc.AccountID equals loc.AccountID
where loc.IsPrimaryLocation == true
orderby loc.Province descending
select acc;
(Basically the above does an on the fly join with another table,
filters it, and then sorts it by a field in the second table,
ultimately returning the accounts sorted.)
I'd like to translate it out of linq syntax to plain old c#, but I've
gotten over my head; the join in particular is really throwing me. If
someone could translate it I'm hoping I'd be able to see the 'pattern'
that it takes. I'd also appreciate being pointed at any resources that
go over this...
Thanks,
Dave