views:

58

answers:

1

Hi All,

I have a relatively modest dataset (probably 20 main tables) but it's queried a lot of different ways.

Sometimes we show a product. Sometimes a product with it's picture. Sometimes a product with it's picture and comments. Sometimes a product with it's picture and all of the users that have the product and their pictures.

etc. (and by "etc." I mean "a LOT more permutations")

LINQ has facilities for making sure our queries grab all of the requisite information via the DataLoadOptions. However, if you want to do things like "just show me 5 comments" you're now using the AssociateWith method on DataLoadOptions, which is now (in my opinion) uncomfortably close to the DB to expose to, say, the codebeside files in your ASPX pages.

So - I'm curious how people handle this? Do they really build a model layer with methods like GetProductsWithPicturesAndUsersAndUserComments(int commentLimit, int pictureSize...

...with every permutation? Especially coming from a Rails background, where they figured this out, this solution seems very ugly. So, I'm hoping there's something else. Wondering what others' experiences are.

Thanks! Tom

+1  A: 

Well, the point of LINQ is that you can compose these kinds of queries yourself. As long as you have the mapping of the model to the database correct, you can query against the representation of the table in code, and then compose that query with Take and it will take the first n rows.

casperOne
From what I've read, it's considered bad form to do things like run "Take" within ASP.NET pages; it's preferable to have your model layer do all of the actual query execution. ie. The pages should be given already-retrieved data, vs those methods and generating new queries. Is that perception wrong?
tlianza