Entity Framework How to prevent a model property from creating columns?

People,

I am developing a web application based on ASP.NET MVC 4.

Let's say I define a model, for example:

public class MyUser {
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}

The database initializer code will automatically create a table with three columns - UserName, FirstName and LastName.

However, let's say I do not want LastName to be part of the database table.

Is there any data annotation attribute that I can use to prevent the object from appearing as a column?

Thank you in advance for your help.

Regards,
Peter

+4
source share
1 answer

NotMapped. , .

public class MyUser {
    public string UserName { get; set; }
    public string FirstName { get; set; }
    [NotMapped]
    public string LastName { get; set; }

}
+7

All Articles