문제

What's the best way of implementing xVal when using the Entity Framework? I've been using this approach but I'd like to know if there's a better way of doing it.

Also I'd like to know if there's a way of doing it without having to raise an exception.

도움이 되었습니까?

해결책

The metadata approach works well, but the approach that I've used is to have a separate set of ViewModel objects and use a tool like AutoMapper to map from the EF objects to the ViewModel objects. (In more complex implementations, there is a separate domain model in between the EF objects and ViewModel objects.)

If you implement a repository pattern to retrieve your ViewModel objects, it also makes testing your controllers a lot easier to do.

You can then attribute your ViewModel objects to your heart's content and not worry about codegen overwriting your attributes. It's also possible to use another validation method (e.g. FluentValidation), since these can be made to work smoothly with xVal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top