【问题标题】:Cannot map property if it does not exist EF如果属性不存在,则无法映射属性 EF
【发布时间】:2016-07-12 16:58:51
【问题描述】:

如果我的属性不存在,实体框架是否可能无法映射它? 现在我有一个 ID,Name,Surname,Type, table 但我没有属性 Email 。 EF 正在映射 ProjectUser 对象属性,该对象具有不在数据库中的属性。总之,如果对象不是数据库,我想维护对象的 Email 属性,但如果有,我想获取值。

namespace Project.IdentityModel.Models {
    public class ProjectUser: IUser<string> {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }//This property no yet into DB.
        public string Surname { get; set; }
        public string Type { get; set; }

}

【问题讨论】:

  • It is possible with entity framework that cannot map my property if it does not exist? 什么?您的问题很难解释,但如果您不想映射属性,请添加 [NotMapped] 属性。

标签: c# asp.net-mvc entity-framework


【解决方案1】:

您可以添加“NotMapped”注释以确保它不会被映射:

[NotMapped]
public string Email { get; set; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2017-09-25
    • 2020-01-01
    • 2023-02-10
    相关资源
    最近更新 更多