具有数据绑定到 ObjectDataSource 的通用 Select 方法?
目前这是一种假设的情况,但我想知道这是否可能。
如果我有这样的方法:
public List<T> SelectEntitiesWithWhere<T>(Func<T, bool> where) where T : EntityObject
{
return this.ObjectContext.CreateObjectSet<T>().Where(where).ToList();
}
是否可以在 DataBound ObjectDataSource 中调用该方法? 可能有这样的代码:
<asp:ObjectDataSource ID="MyODS" runat="server" DataObjectTypeName="MyProgram.EntityFramework.MyEntity"
SelectMethod="SelectEntityWithWhere" TypeName="MyProgram.BusinessLayer.MyCode">
<SelectParameters>
<asp:Parameter Name="where" Direction="Input" DefaultValue="t => t.SomeContactId == contactId" />
</SelectParameters>
我知道事实并非如此,但是这个问题有解决办法吗?如果涉及自定义代码,需要什么?
This is kind of a hypothetical situation at the moment but I'm wondering if it's possible.
If I had a method like this:
public List<T> SelectEntitiesWithWhere<T>(Func<T, bool> where) where T : EntityObject
{
return this.ObjectContext.CreateObjectSet<T>().Where(where).ToList();
}
Would it be possible to call that method in a DataBound ObjectDataSource?
Possibly some code like this:
<asp:ObjectDataSource ID="MyODS" runat="server" DataObjectTypeName="MyProgram.EntityFramework.MyEntity"
SelectMethod="SelectEntityWithWhere" TypeName="MyProgram.BusinessLayer.MyCode">
<SelectParameters>
<asp:Parameter Name="where" Direction="Input" DefaultValue="t => t.SomeContactId == contactId" />
</SelectParameters>
I know that isn't exactly how it would be, but is there some solution to this problem? If custom code was involved, what would it take?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎能够通过将“通用性”从方法转移到类级别来解决部分问题 - 根据 此信息。但这仍然不能解决您的 DefaultValue 要求的问题。
TLDR:您想要的东西是不可能的。
You appear to be able to solve part of the problem by shifting the 'genericity' from the method to the class level - according to this information. But that still doesn't solve the problem of your DefaultValue requirement.
TLDR: What you want isn't possible.