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 开发者_StackOverflowsaved, or not?
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).
精彩评论