Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a user defined function sitting on my SQL server. I want to utilise this within one of the partial entity classes created by the Linq to SQL designer.

I know it's very simple to do when you have access to the datacontext, however in the partial entity classes I obviously don't.

Does anyone know of a way either to access the datacontext that owns a particular entity OR call a udf directly from that entity?

Thanks

share|improve this question
blogs.msdn.com/b/alexj/archive/2009/06/08/… - that might work for you, or you could do some sort of static method on the entity context object that returned a context (checking for thread safety). – Triple Gilaman Jun 7 '12 at 15:08
It looks to me as if that blog is only for Linq to Entities. I'm using Linq to SQL so need a "DataContext" not a an "EntityContext" unfortunately. – Ben Ford Jun 8 '12 at 10:33
It's the same basic concept - navigating 'up' to the context from the object won't work for you out of the box. You need either to put a reference to the context in thread local storage per the blog, add a method to your partial class that gives it the context, or you can have a static method that gives you a context - basically either cache the context (entity or data) in the thread, explicitly make a reference in your partial entities, or make it available to everyone. No great options unfortunately. – Triple Gilaman Jun 8 '12 at 13:41

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.