How to make Fluent API configuration work with MVC client side validation?

后端 未结 2 552
执笔经年
执笔经年 2020-12-28 14:11

I prefer working with Fluent API configuration to DataAnnotation because I want to separate model from data access.

I have tried in MVC, Fluent API does not work wit

2条回答
  •  感动是毒
    2020-12-28 15:11

    No. Fluent API is just mapping - correct. Data annotations are both mapping and validation - wrong. Data annotations are one of the worst features of EF code first because when used this way they couple persistence with presentation and validation logic.

    Advice: don't use EF entities for presentation. Use special view models with data annotations and let your controller prepare view models from entities and vice-versa. Soon or later you will find situations where your validation is not 1:1 with your mapping or where your view needs more or less data than provided in entity type. Use view models and these situations will be handled by them.

提交回复
热议问题