entity-frameworktransient

Does ASP .Net MVC have anything similar to Java's [Transient] attribute?


As the title says, is there a way in ASP .Net MVC (4) to mark a models property as "Transient" i.e. not persist to database.

I am looking to make a model to which most of the data is stored in an external system, I simply need to store a reference of that record in my system and fetch the data from the external system when needed. Am I able to do this using attributes or do I need to implement some sort of View Model?


Solution

  • As it is part of the name of the language, I think that the best practice for you would be to include it in a ViewModel, populate it when you grab the data at first in your controller, and just not do anything with it when you go back to the controller to save it.

    The only thing that comes close to what you're describing is the NotMapped attribute for Entity Framework which will know not to create a column for that field or persist anything to the database for it. But those are typically only used for properties that are precalculated (i.e. you want a quick way to ask for the sum total of 3 of your fields).