I need to call a stored proc from LINQ to SQL. I know that in a database-first approach, you simply drag the stored proc into your LINQ to SQL designer, and the stored proc code will be generated for you.
However, I'm using LINQ to SQL in a code-first approach, where I create my domain classes, and add attributes to hook them up to L开发者_如何学CINQ to SQL. I'm not sure how to call my stored procs this way.
I recommend to do a database-first approach to auto generate the cs code for that, and then implement that code in your (manual) code.
If you implement MySPResult that way, you can use it:
ISingleResult<MySPResult> spResult = DataContext.MySP( params )
Do you need to use LINQ to SQL for this? You can call SP on a DbCommand. If you need to return your POCO entity, you can still convert it manually or write a general entity converter.
(Also consider if you need to use SP at all; you can use standard LINQ, LINQ as expression, dynamic query, then you don't have to implement the otherwise auto-generated typed wrapper code.)
精彩评论