Is it possible to add a property to an entity where the property is not supposed to map to the database?
Asked
Active
Viewed 7,579 times
2 Answers
15
You need to mark the property in the custom partial class to "[NotMapped]". Hope this helps.

Edd
- 703
- 7
- 23
-
2given the question - this should be the accepted answer not sure what the above answer is about... – Saher Ahwal Apr 08 '21 at 22:55
-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
-
1Adding 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