ObjectResult的 C# 扩展方法?
我在实体框架中使用存储过程。假设我有这个过程:
public static int DoSth(decimal id)
{
return (int)Adapter.my_proc(id).First();
}
因为我不想获取 First() 元素,然后每次我想要一个扩展方法来为我执行此操作(获取 First 元素和然后将其转换为 T)。它会是什么样子?
I use stored procedures in Entity Framework. Let's say that I have that procedure:
public static int DoSth(decimal id)
{
return (int)Adapter.my_proc(id).First();
}
as I don't want to get the First() element and then cast it as (int) everytime I'd like to have an extension method which do that for me (gets the First element and then cast it as a T). How will it looks like ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我明白你的问题是什么。以下是简单扩展方法的代码,该方法采用
ObjectResult
,获取集合的第一个元素并将其转换为 T(将该方法放在单独的静态类中)。然后你可以这样称呼它:
这是你的想法吗?
I'm not sure I understand what is your problem. Here is the code for simple extension method that takes
ObjectResult<T>
, gets first element of collections and cast it to T (put the method in separate static class).And then you can call it like:
Is that what you're thinking of?