Reputation: 5
I developed my site with "Database First". With Entity Framework I have a model class User from database. I want to add a property to this class that it won't be in database. How is this possible?
Here is what I tried. User.Custom.cs
[MetadataType(typeof(UserMapping))]
public partial class User
{
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Password does not match")]
[NotMapped]
public string ConfirmNewPassword { get; set; }
public class UserMapping
{
public int Id { get; set; }
public string Username { get; set; }
[DataType(DataType.Password)]
public string Password { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
}
But I am getting the error:
The property 'ConfirmNewPassword' does not exist or is not mapped for the type 'User'.
Can somebody help me please?
Upvotes: 0
Views: 1719
Reputation: 868
It's probably not best approach, but if you insists on using it, try partial class
with attribute NotMappedAttribute
over property, it should work.
If it didn't help, try to use db context configuration
Upvotes: 1