Reputation: 381
This question follows on from previous questions like Does Entity Framework 6 support .NET 4.0?
My question is specifically, how do I make use of the NotMapped
data annotation with EF6 and .NET v4.0?
Most articles I can find assume the developer has also migrated to .NET v4.5 or later, where the data annotations namespace has been moved to System.ComponentModel.DataAnnotations.Schema
and lives in the System.ComponentModel.DataAnnotations
dll.
Upvotes: 1
Views: 4944
Reputation: 381
I solved my own problem (by opening me eyes!). The data entities are in a separate project, which didn't include a reference to Entity Framework. Installing the same EF6 NuGet package in the entities project resolves the issue.
UPDATE: I had further issues with EF6 so I rolled back to EF5 and, instead, created a new ViewModel that included the property I wanted to add to the orginal entity. This maintains the separation of concerns that were compromised in the above solution in a satisfactory manner. It also mirrors the approach taken elsewhere in the code-base.
Upvotes: 0
Reputation:
The .NET 4.0 version of Entity Framework 6 contains a definition of NotMappedAttribute
directly in EntityFramework.dll
. It exists in the same namespace, namely System.ComponentModel.DataAnnotations.Schema
.
You will need to make sure you have the .NET 4.0 version of EF, though. If your project was previously targeting .NET 4.5, and you added EF at that time, you've got the .NET 4.5 version of EF. Changing the project to .NET 4.0 is not enough to fix this. You'll need to remove EF from your project and re-add it.
Upvotes: 3