none
How can I add an additional field to my EF POCO which does not exists in DB? RRS feed

  • Question

  • Hello,

          I am using EF 4.1. I have a situation where I have to add 2 fields which is not map to original table where this Entity is belongs to. Neither I want to save it to Database table. I just want the value for read only purpose. What options I have in EF 4.1 in order to achive this behavior.

         Any help would be appreciated.

     

    Thanks,

     

    Nilkanth Desai

     

    Monday, August 15, 2011 2:36 AM

Answers

  • Hi Nilkanth,

    Welcome!

    There is NotMapped Attribute in Data Annotation.

    NotMappedAttribute 

    Placed on a property or class to exclude it from the database 

    [NotMapped]
        public string Name
        {
          get
          {
            return String.Format("{0} {1}", Title, FirstName);
          }
        }
    
    

    Here is a sample.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Nilkanth Monday, August 15, 2011 8:05 AM
    Monday, August 15, 2011 6:36 AM
    Moderator