2

I'm attempting to include some derived data (calculated on the database) in an entity using 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.

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...

Daniel Neal
  • 4,165
  • 2
  • 20
  • 34

1 Answers1

1

Try using [DatabaseGenerated(DatabaseGeneratedOption.Computed)].

daryal
  • 14,643
  • 4
  • 38
  • 54
  • Thanks! The original error has gone away ("can't update multiple base tables"), but I'm now getting a "Store update, insert, or delete statement affected an unexpected number of rows". Any ideas? – Daniel Neal May 16 '12 at 14:38
  • Refer to: http://stackoverflow.com/questions/1836173/entity-framework-store-update-insert-or-delete-statement-affected-an-unexpec or http://stackoverflow.com/questions/6819813/solution-for-store-update-insert-or-delete-statement-affected-an-unexpected-n – daryal May 16 '12 at 14:41