检查实体是否重复 [英] Checking entity for duplicates

查看:90
本文介绍了检查实体是否重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个实体(OrderHeaders)中有2个字段(InvoiceNumber,OrderNumber),我希望是唯一的,但据我了解,只能使用包含在唯一索引中"每个实体一次.

I have 2 fields (InvoiceNumber, OrderNumber) in an entity (OrderHeaders) that I would like to be unique but as I understand it is only possible use the "include in unique index" option once per entity.

我曾尝试为OrderNumber字段编写自己的自定义验证,但在编写linq查询以搜索实体时有点卡住.我关注了贝丝·马西(Beth Massi)的视频,但这仅用于检查同一屏幕上的重复项.

I have attempted to write my own custom validation for the OrderNumber field but am a little stuck when it comes to writing a linq query to search the entity.  I followed Beth Massi's video but it is only for checking duplicates in the same screen.

在屏幕上输入订单编号后,它需要检查整个OrderHeaders实体,以查看该编号是否已经存在于另一个订单中.此检查可以在保存过程中触发,也可以在输入数字时立即触发 输入该字段.

When an order number is entered on the screen it needs to check the whole of the OrderHeaders entity to see if the number already exists in another order.  This check can be triggered either during the save process or instantly when a number is entered into the field.

这是我到目前为止所拥有的,尽管我不确定它是否正确,我是否需要在某处进行选择声明?

Here is what I have so far although I'm not sure it's correct and do I need a select statement in there somewhere? :

Private Sub OrderNumber_Validate(results As EntityValidationResultsBuilder)
                  If Me.OrderNumber IsNot Nothing Then
                	Dim dupes = (From order In DataWorkspace.ApplicationData.OrderHeaders Where order.OrderNumber IsNot Nothing AndAlso
                                 order.OrderNumber = Me.OrderNumber AndAlso
                                 order IsNot Me)



                If dupes Then
                    results.AddPropertyError("Duplicate order number - there is already an order with the number " & Me.OrderNumber)
                End If
            End If
        End Sub

预先感谢您提供的任何帮助.

Thanks in advance for any help you can provide.

推荐答案

您使用的是哪个版本. VS2013中有一个错误,使包含在唯一索引中"不起作用(但对数据库项目而言是一种简单的解决方法).现在已在Office Developer Tools March'14 Update中包含的LightSwitch v4.5中修复了该问题.那可以防止 重复,您应该这样做.

Which version are you using. There was a bug in VS2013 that made 'Include in unique index' not to work (but an easy workaround with database project). That is now fixed in LightSwitch v4.5 included in Office Developer Tools March'14 Update. That prevents duplicates and you ought to do this.

如果您还希望预先保存自定义验证,请回来,我们可以继续一些代码.

If you want pre-save custom validation as well then get back and we can continue with some code.


这篇关于检查实体是否重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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