实体框架代码首先自定义fieldd,我不想映射到DB

Cal*_*vin 8 entity-framework code-first

我正在使用EF5.在我的域类中,我有一个我不想映射到表的字段.但我必须公开它,以便其他类可以访问它:

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;}
}
Run Code Online (Sandbox Code Playgroud)

当我尝试保存新记录时,上面的代码将生成"无效列LoginFromIP"错误消息,因为我的Person表中没有LoginFromIP.

当我删除setter它工作.我猜EF的自动映射需要getter和setter.如何在不在DB表中创建字段的情况下将LoginFromIP属性保留到域类?

谢谢!

For*_*Two 11

[NotMapped]
public string LoginFromIP {get;set;}
Run Code Online (Sandbox Code Playgroud)