Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework code first custom fieldd that I don't want to map to DB

I'm using EF5. In my domain class I have a field that I do not want to map to the table. But I have to make it public so that other classes can access it:

public class Person
{
   // these are mapped fields
   public string FirstName {get;set;}
   public string LastName  {get;set;}

   // this is intended only for in-memory storage and not saved to DB
   public string LoginFromIP {get;set;}
}

The above code will generated a 'invalid column LoginFromIP' error message when I try to save a new record, because there is NO LoginFromIP in my Person table.

When I remove the setter it works. I guess EF's auto mapping requires both getter and setter. How do I keep my LoginFromIP property to the domain class only without create the field in DB table?

Thanks!

like image 999
Calvin Avatar asked Aug 21 '12 17:08

Calvin


1 Answers

[NotMapped]
public string LoginFromIP {get;set;}
like image 147
Forty-Two Avatar answered Oct 05 '22 11:10

Forty-Two