在OData中引入自定义属性
在我的数据库用户表中,我有名为 DateDeleted 的 DataTime 字段 - 当用户存在时该字段为空,并且当用户“被删除”时设置为正确的值。
我想知道是否有一种方法可以为 User 实体引入 IsDeleted 属性,以便
http://odata/ service.svc/Users(1)/IsDeleted
将根据 DateDeleted 是否设置返回 true 或 false
我在 google 的研究没有得到任何结果,我几乎可以肯定它不可能通过 odata 实现。我说得对吗?
In my database User table I have DataTime field called DateDeleted - which is null while user exists and is set to the proper value when user "is deleted".
I wonder if there is a way to introduce IsDeleted property for User entity so that
http://odata/service.svc/Users(1)/IsDeleted
will return true or false depending on whether DateDeleted is set or not
My research in google hasn't got any results and I am almost sure it is not possible to implement through odata. Am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于内置提供程序,这在 WCF DS 方面是不可能的。您也许能够以某种方式在 EF 端执行此操作(将其公开为 EF 实体的属性),但我不确定这是否可能。
在 WCF DS 方面,您必须实现自定义提供程序才能执行此操作。不幸的是,这可能是相当大量的工作。如果您有兴趣,请参阅以下入门指南:http://blogs.msdn.com/b/alexj/archive/2010/01/07/data-service-providers-getting-started.aspx。
Shawn上面提到的是自定义提供者接口上的方法。
With the built in providers this is not possible on the WCF DS side of things. You might be able to somehow do this on the EF side (expose it as a property of the EF entity), but I'm not sure if that's possible.
On the WCF DS side, you would have to implement a custom provider in order to do this. Which may be quite a lot of work unfortunately. If you're interested see this for starters: http://blogs.msdn.com/b/alexj/archive/2010/01/07/data-service-providers-getting-started.aspx.
What Shawn refers to above is a method on the custom provider interface.
您可以通过实现 DataServiceQueryProvider.GetPropertyValue 方法来指定所需的值。
请在此处查找参考:
http://msdn.microsoft.com /en-us/library/system.data.services.providers.idataservicequeryprovider.getpropertyvalue.aspx
该方法采用两个参数,实体对象(User 实例)和资源属性(在本例中为“IsDeleted”)。您可以尝试从实体对象中获取“DataDeleted”的属性值,并根据需要返回“IsDeleted”的值。
You can specify the value you want by implementing the method DataServiceQueryProvider.GetPropertyValue.
Please find the reference here:
http://msdn.microsoft.com/en-us/library/system.data.services.providers.idataservicequeryprovider.getpropertyvalue.aspx
The method takes two parameters, the entity object (a User instance) and the resource property (in this case "IsDeleted"). You can try to get the property value of "DataDeleted" from the entity object, and return the value of "IsDeleted" as you want.