简体   繁体   English

更新映射到视图的Entity Framework实体

[英]Updating an Entity Framework entity mapped to a view

I'm attempting to include some derived data (calculated on the database) in an entity using Entity Framework Code First. 我试图使用Entity Framework Code First在实体中包含一些派生数据(在数据库中计算)。

To do this, I've created a view which returns the main table, and columns containing the additional derived data. 为此,我创建了一个视图,该视图返回主表以及包含其他派生数据的列。

I've mapped the view to an entity using the [Table("NameOfView")] attribute. 我已经使用[Table("NameOfView")]属性将视图映射到实体。

It seems to work fine for edits, but inserts fail. 似乎可以很好地进行编辑,但是插入失败。 Presumably edits don't attempt to touch the derived fields, but inserts attempt to insert them. 大概编辑不会尝试触摸派生字段,而是插入会尝试插入它们。

Is it possible map entities to views in code first in such a way that a main base table is still updateable, and the columns not intended for updating are ignored? 是否有可能首先以一种方式将实体映射到代码中的视图,使得主基表​​仍可更新,而忽略不打算更新的列?

Or is there another way to do what I'm trying to do? 还是有另一种方式可以做我想做的事?

Note: I've tried to use the [DatabaseGenerated] attribute but that doesn't appear to have helped... 注意:我尝试使用[DatabaseGenerated]属性,但似乎没有帮助...

尝试使用[DatabaseGenerated(DatabaseGeneratedOption.Computed)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM