How to disable automapping of properties in Entity Framework

前端 未结 2 989
太阳男子
太阳男子 2021-01-21 11:10

I\'ve decided to use fluent mapping in Entity Framework. My intention was to map everyting by code without any atributes and auto mapping functions. Best way I\'ve found is clas

相关标签:
2条回答
  • 2021-01-21 11:45

    Actually I have tried a lot of ways: - custom convention to remove mapped properties - removing all conventions

    But the easiest (and cleanest) way was to use reflection inside the mapping class and to disable all property mappings that weren't configured.

    The code for that (and also an usage example) is inside my public gist. https://gist.github.com/hidegh/36d92380c720804dee043fde8a863ecb

    0 讨论(0)
  • 2021-01-21 11:54

    So far as I am aware, there is no other way around it. You need to use either Ignore() or [NotMapped]. I tend to prefer the former as it does not clutter up the model.

    0 讨论(0)
提交回复
热议问题