开发者

How to implement validation with the Massive ORM?

I like Rails and so I'm drawn to Rob Conery's Massive ORM as its ... well, very railsish.

My 开发者_JAVA百科question is how exactly can you and should you do validations with Massive? In Rails you can use the simple "validates" keyword to do inline validations and/or refer to a method to call ... along with the ability to define when such validation takes place (e.g. for create only, after save, etc...).

Are such Rails inspired validations available with Massive? If so, what's the recommended approach?

Thanks much -wg


I was wondering about the same thing today, I still don't really have a satisfactory answer but I did find the sample code for the Tekpub MVC 3 series which has recently been pushed to Github and uses Massive for it's data access -

https://github.com/tekpub/mvc3

This class includes some DataAnnotation validations against view models, as far as I can see none of the 'domain' classes include any validation.


Validations have recently been added to Massive according to the ReadMe on GitHub.


With Asp.net MVC the most recommended approach is to validate using DataAnnotations or FluentValidations. There is a great body of knowledge out there if you just google those terms.

Us Seesharpies prefer to not validate against database models so we can have a clean separation of concerns. Validating database models is not "wrong" but with the rigidity of a static and compiled language other alternative approaches just don't make as much sense.


I wouldn't do validations with Massive. For my domain model I have "command" DTOs which use DataAnnotations. My domain object validates against them and then I use the "domain event" pattern to publish changes to my aggregates.

Here's where I will be using massive - the subscribers listening to my domain will handle the event DTOs that get raised and use them to update the database via massive. Then my view model will use massive to query the database.

I've been using EF 4.1 and I'm sick of mapping command -> event -> view model/dto. I'll use massive so I don't have to define the view model/dto anymore.


doing validation is no different than doing it with EF.. this is meant to be a comment to the above answer.

If you are familiar with DataAnnotations then you know how to do validation. Assuming you have viewmodels then add the annotations to them. In your controllers you are working with the viewmodels where the validation takes place. When validated you are passing these to your data layer which could be massive or ef or whatever.

to be clear, you aren't validating entities you are validating viewmodels.. Hope this makes sense! I barely understand it myself hahahahahah.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜