开发者

Stored Procedure with LINQ, how to work with the dynamic return type

开发者 https://www.devze.com 2023-01-21 16:51 出处:网络
When working with stored procedures in linq, I can go to my SP and select what type of entity it should be returning. This works fine in most cases, except the time\'s I\'m not sure of what will be re

When working with stored procedures in linq, I can go to my SP and select what type of entity it should be returning. This works fine in most cases, except the time's I'm not sure of what will be returned. If I don't select what type of entity to return i get the standard

return ISingleResult<SP-Name>

I thought I would be able to work with this return type like this:

List<SP-Name> myResult = context.SP-Name("London");

But this gives me an error offcourse, about implicit converting ISingleResult to Li开发者_如何学Cst.

How should I do to be able to work with this <SP-Name> returntype?


If you don't specify an entity in your Linq-to-SQL model to be used as the return type for your stored procedure, then Linq-to-SQL autogenerates a type for you.

This is a straight .NET class, so you can inspect its properties and so on - but since it's not one of the entities in you database model, obviously, you cannot save it back to the database and there's no set of that type on your db context, either.

As I said - you can inspect the properties of the return type, you can use that to update other "proper" entities of your Linq-to-SQL model and then save those.

0

精彩评论

暂无评论...
验证码 换一张
取 消