views:

187

answers:

1

Within my database (SQL2008), I have a customer table and a country table (among others) and there is a foreign key relationship defined in the database between these tables based upon "Country.Id -> Customer.CountryId".

I have created an EF model using VS2010 RC and built this model from the database. When generating the model, I selected to include foreign key properties.

After building the model, I selected a number of properties in the "Customer" object, right clicked and selected "Refactor into New Complex Type" which I named "Address". One of the properties that I selected was the CountryId property (actually, it was all of the address properties but I doubt that matters).

Now, when I save the model, I get the error shown above, "There is no property with name 'CountryId' defined in type referred by Role 'Customer'." I know I broke it, but I cannot work out how to fix it again. I can tell you that the "Country" navigation property remains on the Customer object (probably should have included this in the "Address" object too but cannot see how to add this now that I have created the complex type.

I welcome your suggestions!

A: 

My suggestion: Create a new model, map it "right," then copy the relevant bits of CSDL and MSL into your existing model. It may take a couple of tries to do this right, so back up first!

Craig Stuntz
Thanks. I am at such an early stage at the moment that starting from scratch is not a problem. What I really want to know is how to acheive the mapping within my "address" property - I still want to be able to extract the address into its own class and I want the country to be a part of this.
Martin Robins
Complex properties can't contain entities. So either you have to use a scalar or you can't map it.
Craig Stuntz
Thats what I was hoping not to here. Kind of defeats the object in my mind really; especially since nearly all of the examples that I have seen have concentrated on addresses - a very common requirement I would have thought.
Martin Robins
Well, yes, and I'm not saying I agree with the limitation; only explaining the facts.
Craig Stuntz