Pregunta

Working to create an EF6.0 connected DB with MVC5 in VSS2013. Previously the model worked, having been created with EF5.0, MVC3 and VSS2010.

Changes were made to the database on existing tables using MS SQL Express - adding some foreign integer keys on child tables pointing to a master parent record, and a single hand-entered test data record set was created for testing. Some extra properties were added. A couple of new unrelated tables.

The "Update Model From Database" picked up the table changes, but has refused to pick up these FK associations. ALL navigation was missing.

The model was deleted, recreated in EF6.0. Once again the EDMX file picks up all tables, and older FK associations. New ones are simply ignored.

There is no point adding tables here as examples, this is simple Parent Child FK stuff using ints. Scripted SQL shows FK constraints for old and new ones are comparable. I have dropped the model and recreated several times, with different ConnectionStrings, name changing in case of confusion. No joy.

I am totally confused as to why it can pick up some, but not others. I need some "gotcha" clues. Anyone?

EF6.0.0 MVC5.1 .NET4.5

Update: Non-Functional FK example

ALTER TABLE [dbo].[Cli_Address] ADD CONSTRAINT [FK_Cli_Address_WebUserProfileX] FOREIGN KEY ([UserProfileFK]) REFERENCES [dbo].[WebUserProfile] ([UserID]);

¿Fue útil?

Solución

You are hit by this:

http://social.msdn.microsoft.com/Forums/en-US/0ba27be1-d252-44c0-8e0b-7f129b578a2b/missing-navigation-properties-on-entity?forum=adodotnetentityframework

Caused by this unneeded index:

CREATE UNIQUE NONCLUSTERED INDEX [IX_WebProfile] ON [dbo].[WebUserProfile] ( [UserID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO

Dropping the index, and everything Works

(I think you will have to drop and recreate the fks before you can drop the index)

UPDATE: I have fixed this, so this scenario is no longer broken , see https://entityframework.codeplex.com/workitem/667

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top