views:

66

answers:

3

I have tried to find an answer to this, but could not find one in google. Probably not searching the correct terms, so thought I would ask here.

The following returns all my contacts, not the ones that equal the adjusterType sent in.

var contacts = from c in session.Linq<Contact>() select c;
contacts.Where(c => c.ContactAdjuster.AdjusterType == adjusterType);

The following does return the expected results. It does return only the contacts that meet the adjusterType. I believe it is my lack of understanding of LINQ.

var contacts = from c in session.Linq<Contact>() select c;
contacts  = contacts.Where(c => c.ContactAdjuster.AdjusterType == adjusterType);

Thanks in advance.

+2  A: 

the Where clause returns an IEnumerable in your case an IEnumerable. This is the standard LiNQ and C# behavior. Instead of modifying your collection it is returning a new collection based on your where clause.

I suppose NHibernate LiNQ should mimic this.

mhenrixon
+2  A: 

CatZ is absolutely right, you are not modifying the "contacts" collection/enumerable you are creating a new based on the existing, which is why your second statement works.

But instead of just repeating CatZ statement, here is a little add-on:

You can write this in one statement though

var contacts = 
    from c in session.Linq<Contact>() 
    where c.ContactAdjuster.AdjusterType == adjusterType
    select c;

Or simply

var contacts = session.Linq<Contact>().Where(c => c.ContactAdjuster.AdjusterType == adjusterType);
veggerby
A: 

Try using equal rather than =

Where(c => c.ContactAdjuster.AdjusterType.Equals(adjusterType))
newbie