Does ASP.NET MVC have something similar to the Java [Transient] attribute?

As the name says, is there a way in ASP.Net MVC (4) to mark a model property as β€œtransient,” that is, not be stored in the database.

I want to create a model that stores most of the data in an external system, I just need to save a link to this record in my system and, if necessary, get data from an external system. Can I do this using attributes or do I need to implement some kind of View Model?

+4
source share
1 answer

Since this is part of the name of the language, I think that it would be best practice for you to include it in the ViewModel, populate it when you first grab the data in your controller and just don’t do anything when you return to the controller to save it.

The only thing close to what you are describing is the NotMapped attribute for the Entity Framework, which will know that it does not create a column for this field or does not save anything in the database for it. But usually they are used only for pre-calculated properties (i.e. you want to quickly request a sum of three fields).

+3
source

All Articles