4

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?

4

1 回答 1

3

由于它是语言名称的一部分,我认为对你来说最好的做法是将它包含在 ViewModel 中,当你首先在控制器中获取数据时填充它,而当你使用它时不做任何事情返回控制器进行保存。

唯一接近您所描述的是实体框架的 NotMapped 属性,它将知道不为该字段创建列或将任何内容保存到数据库中。但这些通常仅用于预先计算的属性(即您想要一种快速的方法来询问您的 3 个字段的总和)。

于 2013-02-18T14:15:11.513 回答