捕获SQL异常并将其显示在验证摘要中 [英] Catch SQL Exception and display it in validation summry

查看:58
本文介绍了捕获SQL异常并将其显示在验证摘要中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个涉及广泛验证的LightSwitch应用程序.我使用的一种方法是基于属性的验证方法,通过该方法可以检查是否存在重复项.这工作正常,但我发现它太慢了.

I'm writing a LightSwitch application that involves extensive validation. One of the methods I use is the Validate method on one property whereby I check if there are duplicates. This works fine but I find it to be too slow.

当我删除此验证并尝试保存时,该应用程序显示来自SQL Server的错误消息,指出不允许重复.但是,这一次,消息弹出的速度更快.

When I remove this validation and try to save, the application displays the error message from SQL Server saying that no duplicates allowed. However, this time, the message pops up much faster.

由于这要快得多,所以我想尝试捕获VS LightSwitch中的SQL Server错误并在验证摘要"中显示该错误.如何在LightSwitch中完成此操作?

Since this is much faster I'd like to try to catch the SQL Server error in VS LightSwitch and display the error in the Validation Summary. How is this done in LightSwitch?

谢谢!

数据库软件开发人员-蒙特利尔

Database software developer - Montreal

推荐答案

Hi Ray,

Hi Ray,

我想问你的第一件事是关于如何您正在检测重复项.您是否在使用任何语句 是 .Count 吗?如果这样做,则可以通过重新使用查询来发现性能要快得多. .任何.

The first thing I'd like to ask you is about how you're detecting duplicates. Are you using any statements with .Count in it? If you do, you'll find performance is much faster if you rework the query to use .Any instead.

使用 .Count 将所有记录归还给客户端,然后 数他们.因此,您的处理将在客户端层上进行.

Using .Count brings all the records down to the client, then counts them. So your processing happens on the client tier.

使用 .Any ,不会将任何记录传送到服务器,&一个简单的 如果找到匹配的记录,则返回 true/false .在这种情况下,您的处理会在 服务器层.

Using .Any, no records are brought down to the server, & a simple true/false is returned if matching records were found. In this case your processing happens on the server tier.

关于捕获SQL异常的其他想法,取决于其中 您正在捕获异常,则可以通过添加以下内容来使用LightSwitch自己的自定义验证机制: PropertyError PropertyErrors 集合中. (这些名称可能不太正确,但应该可以为您提供总体思路.)

For your other idea of catching the SQL Exception, depending on where you're catching the exception, you may be able to use LightSwitch's own custom validation mechanism, by adding a PropertyError to the PropertyErrors collection. (Those names might not be quite right, but should give you the general idea).


这篇关于捕获SQL异常并将其显示在验证摘要中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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