Exclude Property Mapping In Entity Framework Code First Approach
Hi all,
Given a database table such as User with fields Id, UserName and Password that will be mapped to a class using Entity Framework called User with an additional field of ConfirmPassword.
I would like to exclude the ConfirmPassword field from being mapped to the User table. So, after doing some searching, the solution is to decorate the property with [NotMapped] attribute and make sure to reference the DataAnnotations namespace (System.ComponentModel.DataAnnotations.Schema).
Given a database table such as User with fields Id, UserName and Password that will be mapped to a class using Entity Framework called User with an additional field of ConfirmPassword.
public class User { public int Id { get; set; } public string UserName { get; set; } public string Password { get; set; } public string ConfirmPassword { get; set; } }
using System.ComponentModel.DataAnnotations.Schema; public class User : IEntity { public int Id { get; set; } public string UserName { get; set; } public string Password { get; set; } [NotMapped] public string ConfirmPassword { get; set; } }
Comments
Post a Comment