如何判断给定对象是否已使用 ADO.NET 保存?
如果我有一个新对象,它不是 ADO.NET 中的 context.Saved(),我如何才能将其与另一个尚未保存的对象区分开来?
我将使用此信息来确定如何处理我的自定义自动增量功能。如果该对象已保存到数据库中,我将往返数据库服务器。如果对象尚未保存,那么我将在本地执行自动增量。
那么,给定 2 个 ADO.NET 对象,我如何判断它们是否已保存?
If I have a new object, that is not context.Saved() in ADO.NET, how can I tell that apart from another object that hasn't been saved?
I'm going to use this information to determine how to handle my custom autoincrement feature. If the object has been saved to the database, I'll make a roundtrip to the database server. If the object has not been saved, then I'll perform my auto increment locally.
So, given 2 ADO.NET objects, how can I tell if they have been saved, or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您正在使用 WCF 数据服务(以前称为 ADO.NET 数据服务):
在您的客户端中,您有一个派生自 DataServiceContext 的类的实例。在此实例中,有一个 GetEntityDescriptor 方法,它将实体实例作为参数。它返回一个具有 State 属性的 EntityDescriptor 对象。如果该属性已添加,则意味着新添加的对象尚未保存到服务器。如果 State 属性处于任何其他状态,则意味着该对象已发送到服务器(假设您没有使用一些高级功能,例如调用 AttachTo)。
Assuming you're using WCF Data Services (used to be called ADO.NET Data Services):
In your client you have an instance of a class derived from DataServiceContext. On this instance, there's a method GetEntityDescriptor which takes an entity instance as an argument. It returns an EntityDescriptor object which has a State property. If that property is Added it means the newly added object has not been saved to the server yet. If the State property is in any other state it means that the object has already been sent to the server (assuming you're not using some advanced stuff like calling AttachTo).