Target Framework change 4.0 to 3.5 breaks EF model

2019-06-26 00:57发布

问题:

I created a EF model in a library project which targets .NET framework 4.0. I just downgraded it to target framework 3.5 instead since one of the projects that will be using this library targets 3.5 and cannot be upgraded at the moment.

After changing the target framework from 4 to 3.5, I am getting multiple 111 errors similar to:

Error 111: Properties referred by the Dependent Role WfInstance must be a subset of the key of the EntityType xx.Entity.WfInstance referred to by the Dependent Role in the referential constraint for Relationship xx.Entity.FK_WfInstance_WfStatusType.

What I get out of the message is that my table's (WfInstance) primary key must use/contain the Id of the referenced table (WfStatusType) and any other tables it references. However, I am not sure how to do this.

Any help would be appreciated.

TIA - GP

回答1:

I think you have checked (or left checked) Include foreign keys in the model when you used wizard to create model for .NET 4.0 library. This is a new feature in .NET 4.0 and it cannot be downgraded to .NET 3.5. You will find it easily because your entities will contain properties for foreign key columns. There are some other features which can break downgrading. Anyway believe me if you need model for .NET 3.5 the best way is deleting your EDMX and start from scratch because manually repairing broken model will be damn bad and long task.