I have b开发者_运维技巧een using LINQ with compiled queries, basically passing into the compiled query using Func
but the problem is that it has a maximum of four parameters.
Is it good practice to extend this?
Is there any way to extend this or should I create my own delegate?
Sometimes I need to pass six params and others five and others four or less... so with four or less I could continue using the Func
delegate.
Currently passing in data context and a mix of the params I need are dependent on each individual compiled query.
Just declare your own delegates - it's only a single line of code to do so. See my examples for declaring the .NET 3.5 delegates in .NET 2.0 for a sort of template, if you need it.
I don't know how well this will work with LINQ compiled queries - hopefully it won't be a problem, but your use case isn't quite clear enough to me to say for sure.
Note that in .NET 4.0 there's support for Func/Action with up to 8 parameters.
What Jon said plus...
As you've suggested, generally you shouldnt end up with too many params - generally you should find some uniting concept jumping out telling you to Introduce Parameter Object. Having said that, 4 wouldnt be the place where I'd place a 'that's just crazy' line.
精彩评论