5

Is it possible to add a property to an entity where the property is not supposed to map to the database?

seddler
  • 97
  • 2
  • 6

2 Answers2

15

You need to mark the property in the custom partial class to "[NotMapped]". Hope this helps.

Edd
  • 703
  • 7
  • 23
-2

Possible? Sure; add it to a custom partial class matching your entity type. Useful? Less so; you (mostly) can't use them in LINQ to Entities queries, and you shouldn't re-purpose your entities as view models.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
  • 1
    Adding properties in an partial class works fine when reading from database to display info on screen. But when I'm saving an entity I get an error telling me that the column (the added property) does not exist. How can I avoid thid issue? Any thoughts? – seddler May 18 '10 at 09:40
  • I can't give a useful answer with only a vague description of the error you're seeing and nothing precise about what you're doing. The source code, the exact error, and a call stack is really a minimum for "debugging over the web." – Craig Stuntz May 18 '10 at 12:39