I am working on an asp.net mvc-5 web application, and i am using entity framework 5.0. I have mapped my SQL server database tables which created an .edmx
file. now i want to extend the model classes to have additional non-database attributes, so i created a partial class for my model class and i provided an additional attribute as follow:-
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Test.Models
{
public partial class User
{
[NotMapped]
public string NonDataBaseColumn { set; get; }
}
}
so i have these questions:
- is this a valid approach to pass additional attributes , by defining additional columns inside the partial classes.
- since i am using database first approach, so do i need to add
[NotMapped]
data annotation, or the[NotMapped]
is only valid when following code-first approach ? - could under any situation the NotMapped column (NonDataBaseColumn in my case) get created inside the Databse automatically ?