Greg Foote
Greg Foote

Reputation: 171

EF Code First NotMapped Attribute?

I have properties on my POCOs like the following that allow me to easily access identifying criteria that a user will be able to associate an entity record with for use in my auditing and validation code...

Sometime the Identifer is a simple concatenation of 2 or more scalar fields, and sometimes it has code in it to retrieve and concatenate properties on a Navigation Reference.

I don't need to store this data with each entity in the DB, BUT I do want to be able to access it thru the DbEntityEntry, I tried decorating it with [NotMapped] but then it is not accessible on my entity ?

    [Identifer]
    public string Identifer 
    {
        get { return HRContact.Identifer; }
        set { }
    }

Anyone know how to accomplish this ?

Thanks Greg

Upvotes: 0

Views: 1297

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364399

I'm not sure what you mean be accessing those data through DbEntityEntry. DbEntityEntry contains reference to entity in Entity property - there you will get access to any properties the entity provides. DbEntityEntry also holds collection of current values and original values. These collections will always contain only mapped (persisted) properties because EF never deals with not mapped properties.

Upvotes: 1

Related Questions