开发者

Correct association mapping in Entity Framework

Trying to change two relationships in our entity framework from many-to-one to many-to-many relationships. So I tried the obvious thing: clicked on each association on the diagram, changed the appropriate end of the association accordingly and then changed the name of the navigation property to a plural to reflect the change.

This lead to the following build error, or one each for the two changes I've made:

Error 3002: Problem in mapping fragments starting at line 1761:Potential runtime violation of table CustomerServices's keys (CustomerServices.Id): Columns (CustomerServices.Id) are mapped to EntitySet CompiledDatabaseCustomerService's properties (CompiledDatabaseCustomerService.CustomerService.Id) on the conceptual side but they do not form the EntitySet's key properties (CompiledDatabaseCustomerService.CompiledDatabase.Id, CompiledDatabaseCustomerService.CustomerService.Id)

I'm not entirely sure why this is happening, so unsurprisngly I haven't had much luck fixing it. I've tried fiddling with the mapping details and adding referential constraints to no avail. Anyone point me in the right direct开发者_Go百科ion?

cheers, Matt


One of the first things to check when you get this error is to look and make sure that the key columns in your database schema match your entity definitions. I ran into a similar problem when I was doing an update.

If this doesn't appear to be your problem, then also check that you have not flipped the columns with respect to your mapping - make sure everything is mapping in the correct direction. (I would recommend looking at your mappings directly to see if this is what is happening.)


OK, it turns out all that's required is to update the database from the model. Idiot me - I thought that only regenerated the SQL scripts to create the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜