What's the convention for extending Linq with set based helper operations

Posted by Luke Rohde on Stack Overflow See other posts from Stack Overflow or by Luke Rohde
Published on 2010-03-30T08:42:34Z Indexed on 2010/03/30 8:43 UTC
Read the original article Hit count: 532

Filed under:
|
|
|
|

Hi All

I might be vaguing out here but I'm looking for a nice place to put set based helper operations in linq so I can do things like;

db.Selections.ClearTemporary()

which does something like

db.DeleteAllOnSubmit(db.Selections.Where(s => s.Temporary))

Since I can figure out how to extend Table<Selection> the best I can do is create a static method in partial class of Selection (similar to Ruby) but I have to pass in the datacontext like;

Selection.ClearTemporary(MyDataContext)

This kind of sucks because I have two conventions for doing set based operations and I have to pass the data context to the static class.

I've seen other people recommending piling helper methods into a partial of the datacontext like;

myDataContext.ClearTemporarySelections();

But I feel this makes the dc a dumping ground for in-cohesive operations.

Surely I'm missing something. I hope so. What's the convention? TIA

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about helper