Linq to SQL - Best way to work with a collection of objects inside another object?

How about this one (slightly more simple syntax).

How about this one (slightly more simple syntax): Updated where clause due to comment from I in db. Items where i. AuctionID == 2 && i.Bids.

Any(c=>c. CustomerID == (Int32? )1165) select new { i.

ItemId, i. ItemName, i.Bids. Where(b=>b.

CustomerID == (Int32?)1165 ). OrderbyDescending(b=>b. BidTime) } Make sure you profile the sql and verify that you get only ONE sql statement.

If not, you need to have to add LoadOptions to your datacontext (that will make sure all the bids are eager loaded with your items). This one will also order the bids per item (not sure if yours will do the same.... but I guess you checked that).

Thanks Pleun! I had to make a couple edits to fix up the anonymous type. You are correct in assuming I wanted the Bids ordered by BidTime within each Item.

There is one problem with the result set. It returns every Item in the Items table and only populates the Bids IEnumerable for the Items Customer 1165 bid on. I would like the return set to only include the Items 1165 bid on.

Thanks! – BKahuna Sep 30 '11 at 16:04 BTW: You do not need the "from be in i. Bids" => that is already there due to the foreign key and is handled by Linq2sql – Pleun Sep 30 '11 at 16:54 See updated where clause, but might not be the best solution – Pleun Sep 30 '11 at 16:57 Actually I tried that (without the 'from bin i.

Bids') and then Linq can't find CustomerID or BidTime (both fields in the Bids table). I was able to resolve that by adding the second 'From'. I agree with you, I thought that because of the FK I could access it directly but it didn't seem to work.

– BKahuna Sep 30 '11 at 17:37 Well, i. Bids is a collection (multiple bids) so it does not have a customerID so you need to use things like . Any .

First etc. – Pleun Sep 30 '117 at 9:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions