My understanding is that the [NotMapped]
attribute is not available until EF 5 which is currently in CTP so we cannot use it in production.
How can I mark properties in EF 4.1 to be ignored?
UPDATE: I noticed something else strange. I got the [NotMapped]
attribute to work but for some reason, EF 4.1 still creates a column named Disposed in the database even though the public bool Disposed { get; private set; }
is marked with [NotMapped]
. The class implements IDisposeable
of course but I don't see how that should matter. Any thoughts?
Best Answer
You can use the
NotMapped
attribute data annotation to instruct Code-First to exclude a particular property[NotMapped]
attribute is included in theSystem.ComponentModel.DataAnnotations
namespace.You can alternatively do this with
Fluent API
overridingOnModelCreating
function in yourDBContext
class:http://msdn.microsoft.com/en-us/library/hh295847(v=vs.103).aspx
The version I checked is
EF 4.3
, which is the latest stable version available when you use NuGet.Edit : SEP 2017
Asp.NET Core(2.0)
Data annotation
If you are using asp.net core (2.0 at the time of this writing), The
[NotMapped]
attribute can be used on the property level.Fluent API