CodeSmith Community
Your Code. Your Way. Faster!

Add the [DataMember] attribute to EntityState, IsDeleted, IsNew etc.

Latest post 07-25-2007 1:56 PM by Don. 1 replies.
  • 07-09-2007 10:13 PM

    • Jimmy
    • Not Ranked
    • Joined on 07-09-2007
    • Posts 3
    • Points 75

    Add the [DataMember] attribute to EntityState, IsDeleted, IsNew etc.

    Would it be possible to add the WCF [DataMember] attribute to the properties like those above on Entity classes? This information gets lost when sending these objects accross the wire from a WCF service to a client app and back again.

     A simple example of the consequences of this is:

    - Client requests MyClass with Id = "Foo" from the server... this is an existing object but when the "streamed" object arrives on the client, WCF creates a new instance of MyClass (which now has IsNew == true)

    - Client modifies MyClass

    - Client sends MyClass back to the server to be saved. Again, this is an existing object, but when the Service method that is trying to Save this class attempts to save it, it will result in an Insert statement rather than an Update - which will of course cause a key violation on the primary key colum.

    I'm working around this currently by checking, server side, if an object exists in the databases or not before saving that object. If it does I'm setting the EntityState to EntityState.Changed before executing the EntityProvider.Save operation but this doesn't handle deletes at all... so a WCF service requies separate Save and Delete methods (the first can deal with Inserts and Updates and the later with Deletes) and it also makes it very difficult to handle combinations of these three operations in a single transaction/batch...

    So basically, things would be much easier if Entities didn't loose their state information when they were serialized (for example when streaming them across the wire in WCF)... and I think that could be achieved simply by whacking the [DataMember] attribute onto a few extra properties for each of the entities (at the moment this is only used to decorate Data properties).

     
    Thanks in advance.

     
    Jimmy 


     

    • Post Points: 35
  • 07-25-2007 1:56 PM In reply to

    • Don
    • Top 100 Contributor
    • Joined on 11-03-2006
    • Posts 48
    • Points 1,000

    Re: Add the [DataMember] attribute to EntityState, IsDeleted, IsNew etc.

     I'm noticing a similar issue when handing back an entity object to an ObjectDataSource from my business layer.  It seems that the IsNew flag is always set even when it's an existing object, resulting in a primary key violation when I call the save.

     Is this by design?
     

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems