如何使用Massive ORM实现验证?

时间:2021-12-30 05:27:51

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

我喜欢Rails,所以我被Rob Conery的Massive ORM所吸引......好吧,非常棒。

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...).

我的问题是你究竟能够和你应该如何使用Massive进行验证?在Rails中,您可以使用简单的“validates”关键字来进行内联验证和/或引用一个方法来调用...以及定义何时进行此类验证的能力(例如,仅用于创建,保存后等)。 )。

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

是否有这样的Rails激发了Massive的验证?如果是这样,推荐的方法是什么?

Thanks much -wg

非常感谢-wg

5 个解决方案

#1


1  

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

根据GitHub上的ReadMe,最近在Massive中添加了验证。

#2


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 -

我今天想知道同样的事情,我仍然没有真正得到满意的答案,但我确实找到了Tekpub MVC 3系列的示例代码,该代码最近被推送到Github并使用Massive进行数据访问 -

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.

此类包含针对视图模型的一些DataAnnotation验证,据我所知,“域”类都不包含任何验证。

#3


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.

使用Asp.net MVC,最推荐的方法是使用DataAnnotations或FluentValidations进行验证。如果你只是谷歌这些条款,那里有很多知识。

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.

我们Seesharpies更喜欢不对数据库模型进行验证,因此我们可以清楚地分离关注点。验证数据库模型并非“错误”,但由于静态和编译语言的刚性,其他替代方法并没有那么多意义。

#4


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.

我不会对Massive进行验证。对于我的域模型,我有“命令”使用DataAnnotations的DTO。我的域对象验证它们,然后我使用“域事件”模式将更改发布到我的聚合。

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.

这里我将使用大量的内容 - 收听我的域的订阅者将处理被引发的事件DTO并使用它们通过大量更新数据库。然后我的视图模型将使用大量来查询数据库。

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.

我一直在使用EF 4.1,我厌倦了映射命令 - >事件 - >视图模型/ dto。我将使用大量的,所以我不必再定义视图模型/ dto了。

#5


0  

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

进行验证与使用EF进行验证没有什么不同。这是对上述答案的评论。

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.

如果您熟悉DataAnnotations,那么您就知道如何进行验证。假设您有视图模型,然后添加注释。在控制器中,您正在使用进行验证的视图模型。验证后,您将这些传递给您的数据层,这可能是巨大的或ef或其他。

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

要清楚,你没有验证你正在验证视图模型的实体..希望这是有道理的!哈哈哈哈哈,我几乎不懂。

#1


1  

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

根据GitHub上的ReadMe,最近在Massive中添加了验证。

#2


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 -

我今天想知道同样的事情,我仍然没有真正得到满意的答案,但我确实找到了Tekpub MVC 3系列的示例代码,该代码最近被推送到Github并使用Massive进行数据访问 -

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.

此类包含针对视图模型的一些DataAnnotation验证,据我所知,“域”类都不包含任何验证。

#3


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.

使用Asp.net MVC,最推荐的方法是使用DataAnnotations或FluentValidations进行验证。如果你只是谷歌这些条款,那里有很多知识。

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.

我们Seesharpies更喜欢不对数据库模型进行验证,因此我们可以清楚地分离关注点。验证数据库模型并非“错误”,但由于静态和编译语言的刚性,其他替代方法并没有那么多意义。

#4


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.

我不会对Massive进行验证。对于我的域模型,我有“命令”使用DataAnnotations的DTO。我的域对象验证它们,然后我使用“域事件”模式将更改发布到我的聚合。

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.

这里我将使用大量的内容 - 收听我的域的订阅者将处理被引发的事件DTO并使用它们通过大量更新数据库。然后我的视图模型将使用大量来查询数据库。

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.

我一直在使用EF 4.1,我厌倦了映射命令 - >事件 - >视图模型/ dto。我将使用大量的,所以我不必再定义视图模型/ dto了。

#5


0  

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

进行验证与使用EF进行验证没有什么不同。这是对上述答案的评论。

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.

如果您熟悉DataAnnotations,那么您就知道如何进行验证。假设您有视图模型,然后添加注释。在控制器中,您正在使用进行验证的视图模型。验证后,您将这些传递给您的数据层,这可能是巨大的或ef或其他。

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

要清楚,你没有验证你正在验证视图模型的实体..希望这是有道理的!哈哈哈哈哈,我几乎不懂。