Have model contain field without adding it to the database? [closed] Have model contain field without adding it to the database? [closed] asp.net asp.net

Have model contain field without adding it to the database? [closed]


Just decorate your field/property with [NotMapped].

For example:

public class MyModel{    public int Id { get; set; }    public string Name { get; set; }    [NotMapped]    public string Type { get; set; }}

See http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.notmappedattribute.aspx


That depends what framework you are using to access your data. I assume it's Entity Framework. Well, you can create partial class with the property that you wanty to not be mapped to your database.

something like

public class Class1{    string Text { get; set; }    int Number { get; set; }}public partial class Class1{    bool IsSomething { get; set; }}

but that is not advised. More:Entity Framework: add property that don't map to database

Or if you're using Code First:Ignoring a class property in Entity Framework 4.1 Code First