I add a web service (ASMX) to my VS2010 project via "Add Service Reference". This generates proxy classes in the Reference.cs file. Some of these classes are the return values for the methods that I call on the web service. I'm trying to persist these classes to my SQL Server database using Entity Framework 4.1 "Code First".
The problem that I run into is that these classes have no "key" defined. So that when I try to save the returned objects using EF, I get error messages like "EntityType 'MyReturnObject' has no key defined. Define the key for this EntityType" and a corresponding error message for the EntitySet.
What I'd like to do is add an identity column to the generated table for each class. I've done some research on the web and the place to do it would seem to be in the "OnModelCreating" event on my DbContext based class for my data model.
i.e. something like
protected override void OnModelCreating(DbModelBuilder modelbuilder) { modelBuilder.Entity<TheReturnObject>().AddProperty("MyNEWIdentityColumnName")...blah } where ... blah is whatever additional fluent config info is needed to tell EF to make this an identity column in the SQL Server database.
Intellisense tells me that there is no AddProperty method for Entity so just treat that as my way of indicating what I need, I'm aware it doesn't exist.
Then I also want any of the immediate child objects in the object graph to use that as their foreign key reference when saving. These child objects also have children so they need their own identity columns too, and so on.
If these were my own POCOs, I could just add the relevant properties and attributes to the classes in the source, but since they are proxies, I don't see doing that as an option.
Maybe I'm not seeing the forest for the trees, here. I'd greatly appreciate any advice in this matter.