Adding a custom property to a client side class

I need to add a custom property to the Entity Framework class, but when I do this, I get "XXX property name specified for type XXX is invalid." error. Is there any attribute that I can provide for the property, so it is ignored and not mapped to anything?

Edit: if I add a custom property, as in the Martin example below, the following code will raise the above error when calling SaveChanges.

MyEntities svc = new MyEntities(url); MyEntity ent = new MyEntity(); ent.MyField = "Hello, world"; svc.AddMyEntity(ent); svc.SaveChanges(); 
+4
source share
2 answers

Here is the answer: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/b7a9e01d-c5c2-4478-8f01-00f7f6e0f75f

Edit: The best link describes the final compact response of adding an attribute to prevent Entity from serializing when sent to the service.

+1
source

You can add a property to the code:

 public partial class MyEntity { public String MyCustomProperty { get; set; } } 

Entity Framework generates partial classes that allow you to customize the generated class.

Also, in order to comment on your code, I think it should change it to something like this:

 MyEntities svc = new MyEntities(url); // Create MyEntity using the factory method. MyEntity ent = MyEntities.CreateMyEntity(...); ent.MyField = "Hello, world"; svc.AddMyEntity(ent); svc.SaveChanges(); 

This will ensure that your object is properly initialized.

+2
source

All Articles