In my Asp.NET MVC4 application I want to add a field to my model without adding it to the database.
Sort of a field that only lives in c# instances of the model but not in the database itself.
Is there any annotation or other way to exclude the field from the database itself?
I mean an object I can read and write in runtime which the database has no knowledge of.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With