c# - WCF Data services SaveChanges not firing WritingEntity event -
i using wcf data services (5.6 now) , since enums not supported (and other reasons), have additional properties added client side classes intend remove during savechanges using writingentity event following example in http://blogs.msdn.com/b/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado-net-data-services-client-library.aspx
my constructor attaches event find event fires , other times (more often) doesn't.
public mydatacontext(system.uri serviceroot, bool ignoreproperties) : this(serviceroot) { if (ignoreproperties) this.writingentity += edicontext_writingentity; this.sendingrequest2+=onsendingrequest; }
to save changes
db.attachto("maps", map, "*"); db.updateobject(map); processmapcoordinates(db, map); processmodifiers(map, db); db.savechanges();
the sendingrequest2 event fire, use attach header information request in order support multiple data
private void onsendingrequest(object sender, sendingrequest2eventargs e) { e.requestmessage.setheader("profile", clientsettings.instance.profile); }
does know under circumstances writingentity event not fire?
is there way prevent extended properties partial class being serialized?
thanks
it appears caused use of public enums on client side partial class. once changed access modifier of enum internal problem went away.
in process learned better way of controlling properties serialized, hooking requestpipeline events:
if (ignoreproperties) { this.configurations.requestpipeline.onentrystarting((a => { entitytype = type.gettype(a.entry.typename); if (entitytype != null) { var props = entitytype.getproperties() .where( property => property.getcustomattributes(typeof (donotserializeattribute), false).length > 0) .select(p => p.name) .toarray(); a.entry.removeproperties(props); } })); }
Comments
Post a Comment