How to implement validation with the Massive ORM?
Asked Answered
D

5

6

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

My 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

Digestif answered 9/7, 2011 at 0:49 Comment(0)
B
1

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

Bladderwort answered 30/9, 2011 at 17:39 Comment(0)
S
2

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.

Senhorita answered 15/7, 2011 at 21:52 Comment(1)
Yup. View Model validation is great but if you can't do it in domain then you fail. I'm sure its possible ... the question is how and is it both intuitive & flexible (like Rails 'validations').Digestif
N
1

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.

Nightjar answered 9/7, 2011 at 1:24 Comment(1)
My question is HOW you would implement such validation with Massive? I'm familiar with, and use, both DataAnnotations and other attribute based validation mechanisms ... but I'm not sure how you would do such using Massive. ThanksDigestif
A
1

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.

Atonic answered 22/9, 2011 at 16:39 Comment(0)
B
1

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

Bladderwort answered 30/9, 2011 at 17:39 Comment(0)
N
0

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.

Nichollenicholls answered 12/7, 2011 at 22:24 Comment(1)
Validation should be a part of your DOMAIN model, not your VIEW models in order to stay DRY and ensure validation happens regardless of client (browser, web service, mobile app, etc...). Again, I'm looking for a concrete example of validation in the domain model that utilizes the Massive ORM.Digestif

© 2022 - 2024 — McMap. All rights reserved.