Reputation: 8159
I need to add a custom property to an Entity Framework class, however when I do I get the "The property name XXX specified for type XXX is not valid." error. Is there some attribute I can give the property so it is ignored and not mapped to anything?
Edit: If I add a custom property, as per Martin's example below, then the following code will raise the above error at the SaveChanges call.
MyEntities svc = new MyEntities(url);
MyEntity ent = new MyEntity();
ent.MyField = "Hello, world";
svc.AddMyEntity(ent);
svc.SaveChanges();
Upvotes: 4
Views: 9091
Reputation: 8159
Here is the answer: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/b7a9e01d-c5c2-4478-8f01-00f7f6e0f75f
Edit: A better link describes the final compact answer of Adding an Attribute to prevent serialization of the Entity when sending to the Service.
Upvotes: 1
Reputation: 106816
You can add a property in code:
public partial class MyEntity {
public String MyCustomProperty {
get;
set;
}
}
The Entity Framework generate partial classes enabling you to customize the generated class.
Also, to comment on your code I think 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 entity is properly initialized.
Upvotes: 2