I have a webservice that retuns entity framework objects. On the calling side, I don't do anything but read the information, so I don't need these entity framework serialization attributes. Is it possible to remove the following serialized text when returning entity framework objects?
<EntityKey> <EntitySetName>ClassName</EntitySetName> <EntityContainerName>MyEntities</EntityContainerName> -<EntityKeyValues> -<EntityKeyMember> <Key>ClassID</Key> <Value xsi:type="xsd:int">9903</Value> </EntityKeyMember> </EntityKeyValues> </EntityKey>
I've read up on how EF would require me to make a bunch of POCOs and such, which required me to do a lot of work. I decided to think about it some more and did some digging on the Entity object. After seeing that it wasn't sealed, I created a custom class that inherits from this class and added a 'new' statement to the EntityKey field with the XmlIgnore attribute. Going back to my EF designer class, I changed all classes to inherit from CustomEntityObject instead and voila!, no unneccessary fields. Whether this is future proof, I doubt it. But for this project, it works great and it didn't require me to write DTOs for all my classes. Hopefully someone else finds it useful:
public class CustomEntityObject : EntityObject {
[DataMember]
[Browsable(false)]
[XmlIgnore]
public new EntityKey EntityKey { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With