如何从实体验证中设置AddPropertyError [英] How to set an AddPropertyError from an entity validation

查看:65
本文介绍了如何从实体验证中设置AddPropertyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在执行实体验证时在屏幕上显示字段(属性?)错误。我不想通过执行AddEntityError获得的摘要错误消息,我实际上想要红色大纲和相关消息。这是我的实体
验证...


       私人小组AccountingPeriods_Validate(实体作为AccountingPeriod,结果如EntitySetValidationResultsBuilder)

            Dim booOverlap As Boolean

            Dim evb As Microsoft.LightSwitch.EntityValidationResultsBuilder    "我不知道什么样的价值分配给该



            '检查重叠日期范围

           对于每个REC作为AccountingPeriod在Me.qAccPdsByStartDate

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果rec.Id<> entity.Id然后

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; booOverlap = CheckDateOverlap(entity.StartDate,entity.EndDate,rec.StartDate,rec.EndDate)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果booOverlap然后

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP; "我想设置一个属性错误FROM HERE - 如何

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; "evb.AddPropertyError(QUOT;日期重叠的另一范围")



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;结束如果

               结束如果

           下一个

 

       结束小组


吉姆
解决方案

我认为你正在寻找如何要为实体类型的特定属性添加自定义验证代码,是否正确?


如果您在实体设计器中打开了实体,请在设计器的数据网格中选择该属性,单击"编写代码"下拉到设计器工具栏上,然后选择< PropertyName> _Validate。在运行时,如果用户输入的值未通过此处为此属性编写的
验证代码,则将显示该特定属性的验证错误(红色大纲)。


您在帖子中编写代码的方法是为整个实体添加验证,而不仅仅是特定属性。


I want a field (property?) error to appear on a screen as a consequence of doing an entity validation. I don't want the summary error message you get by doing an AddEntityError, I actually want the red outlining and associated message. Here is my entity validation...

        Private Sub AccountingPeriods_Validate(entity As AccountingPeriod, results As EntitySetValidationResultsBuilder)
            Dim booOverlap As Boolean
            Dim evb As Microsoft.LightSwitch.EntityValidationResultsBuilder    'I DON'T KNOW WHAT VALUE TO ASSIGN TO THIS

            'Check for overlapping date range
            For Each rec As AccountingPeriod In Me.qAccPdsByStartDate
                If rec.Id <> entity.Id Then
                    booOverlap = CheckDateOverlap(entity.StartDate, entity.EndDate, rec.StartDate, rec.EndDate)
                    If booOverlap Then
                        'I WANT TO SET A PROPERTY ERROR FROM HERE - HOW?
                        'evb.AddPropertyError("Date overlaps another range")

                    End If
                End If
            Next
 
        End Sub


Jim

解决方案

I think you are looking for how to add custom validation code for a particular property on an entity type, correct?

If you have the entity open in the entity designer, select the property in the data grid of the designer, click the Write Code drop down on the designer tool bar, and select <PropertyName>_Validate. At runtime, if a user enters a value that fails the validation code you wrote here for this property, then the validation error (red outlining) will show for that particular property.

The method that you are writing code for in your post is to add validation for the entire entity, not just a particular property.


这篇关于如何从实体验证中设置AddPropertyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆