从WCF数据服务运行自定义逻辑 [英] Running custom logic from a WCF Data Service

查看:89
本文介绍了从WCF数据服务运行自定义逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个连接到EF4实体模型的wcf数据服务.作为保存我的一个实体的一部分,我想运行一些自定义逻辑.

为此,我使用了一个变更拦截器,该拦截器在实体保留到数据库之前调用自定义逻辑.但是问题是,我的某些逻辑要求保存对象的实体ID,如果操作是插入操作,则还没有生成.

所以问题是,在实体被持久保存到数据库之后,如何从WCF数据服务中运行自定义逻辑?

预先感谢您的任何答复

Ryan

Hi all,

I have a wcf data service wired up to an EF4 entity model. As part of the saving of one of my entities, I want to run some custom logic.

To do this I''ve used a change interceptor which calls out to custom logic prior to the entity being persisted to the database. The problem however, is that some of my logic requires the entity id of the object being saved, which, if the operation is an insert, hasn''t been generated yet.

So the question is, how do I run custom logic from my WCF data service, after the entity has been persisted to the database?

Thanks in advance for any replies

Ryan

推荐答案

OP是去年发布的,但将来可能与之相关的我建议使用事务处理.因此,将插入内容包装在事务中,您可以通过从存储过程中返回@@ identity来获取ID,对ID进行任何操作,如果一切正常,则提交事务,否则不要,也不会插入记录.
The OP was from last year but for whom it may concern in the future I would suggest using transactions. So, wrap the insert in a transaction, you''ll be able to get your id by an @@identity being returned from say a stored procedure, do whatever with the id and if things are good with it then commit the transaction, else don''t and the record won''t be inserted.


据我所知,这看起来不太可能.最好的解决方法是在需要调出业务逻辑或对保存过程有更多控制的情况下,使用标准的WCF服务.在不需要在保存过程中运行自定义逻辑的情况下,可以最好地提供数据服务.
As far as I can tell, this doesn''t look possible. The best workaround is to use a standard WCF service for situations where you need to call out to business logic, or have more control over the save process. Data services are best served in scenarios where you do not need to run custom logic as part of the saving process.


这篇关于从WCF数据服务运行自定义逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆