LinqDataSourceValidationException LinqDataSourceValidationException LinqDataSourceValidationException LinqDataSourceValidationException Class

定义

描述在 LinqDataSource 控件插入、更新或删除值之前验证新值或修改后的值期间发生的异常。Describes an exception that occurred during validation of new or modified values before values are inserted, updated, or deleted by a LinqDataSource control.

public ref class LinqDataSourceValidationException : Exception, System::Web::DynamicData::IDynamicValidatorException
[System.Serializable]
public class LinqDataSourceValidationException : Exception, System.Web.DynamicData.IDynamicValidatorException
type LinqDataSourceValidationException = class
    inherit Exception
    interface IDynamicValidatorException
    interface ISerializable
Public Class LinqDataSourceValidationException
Inherits Exception
Implements IDynamicValidatorException
继承
LinqDataSourceValidationExceptionLinqDataSourceValidationExceptionLinqDataSourceValidationExceptionLinqDataSourceValidationException
属性
实现

示例

下面的示例演示Updating事件的事件处理程序。The following example shows an event handler for the Updating event. 它通过使用Label控件显示任何验证异常消息。It displays any validation exception messages by using a Label control.

Protected Sub LinqDataSource_Updating(ByVal sender As Object, _  
        ByVal e As LinqDataSourceUpdateEventArgs)  
    If (e.Exception IsNot Nothing) Then  
        For Each innerException As KeyValuePair(Of String, Exception) _  
               In e.Exception.InnerExceptions  
            Label1.Text &= innerException.Key & ": " & _  
                innerException.Value.Message & "<br />"  
        Next  
        e.ExceptionHandled = True  
    End If  
End Sub  
protected void LinqDataSource_Updating(object sender,   
        LinqDataSourceUpdateEventArgs e)  
{  
    if (e.Exception != null)  
    {  
        foreach (KeyValuePair<string, Exception> innerException in   
             e.Exception.InnerExceptions)  
        {  
        Label1.Text += innerException.Key + ": " +   
            innerException.Value.Message + "<br />";  
        }  
        e.ExceptionHandled = true;  
    }  
}  

注解

LinqDataSourceValidationException类包含类型转换和属性 setter 异常。The LinqDataSourceValidationException class contains type conversion and property setter exceptions. 在验证过程中引发的所有异常都包含在InnerExceptions集合中。All of the exceptions that are thrown during validation are contained in the InnerExceptions collection. 可以通过循环访问InnerExceptions集合来检索每个验证异常。You can retrieve each validation exception by iterating through the InnerExceptions collection.

通常会在UpdatingDeletingInserting事件中处理异常。You typically handle exceptions in the Updating, Deleting, and Inserting events. 如果引发验证异常, ExceptionLinqDataSourceUpdateEventArgsLinqDataSourceDeleteEventArgsLinqDataSourceInsertEventArgs对象的属性将包含一个LinqDataSourceValidationException对象。If a validation exception is thrown, the Exception property of the LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, or LinqDataSourceInsertEventArgs object contains a LinqDataSourceValidationException object. 如果未引发异常, 则属性Exception将包含nullIf no exception is thrown, the Exception property contains null.

若要处理验证异常, 请为UpdatingDeletingInserting事件创建处理程序。To handle validation exceptions, create a handler for the Updating, Deleting, or Inserting event. 在事件处理程序中, 检查事件Exception参数类的属性是否包含以外null的值。In the event handler, check whether the Exception property of the event argument class contains a value other than null. 如果属性不为 null, 则引发一个或多个验证异常, 你可以InnerExceptions在属性中检索每个验证异常。 ExceptionIf the Exception property is not null, one or more validation exceptions were thrown and you can retrieve each validation exception in the InnerExceptions property.

如果值与属性的类型不匹配, 则会发生验证异常。A validation exception can occur if a value does not match the type of the property. 例如, 尝试使用非数字字符更新整数属性会导致验证异常。For example, trying to update an integer property by using non-numeric characters causes a validation exception. LINQ to SQL 类还可以包含自定义验证条件, 这些条件可确保属性包含的值在预期范围或模式内。A LINQ to SQL class can also contain customized validation criteria that make sure that the property contains a value that is within an expected range or pattern.

构造函数

LinqDataSourceValidationException() LinqDataSourceValidationException() LinqDataSourceValidationException() LinqDataSourceValidationException()

使用由系统提供的用于描述错误的消息初始化 LinqDataSourceValidationException 类的新实例。Initializes a new instance of the LinqDataSourceValidationException class with a system-supplied message that describes the error.

LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext)

用序列化数据初始化 LinqDataSourceValidationException 类的新实例。Initializes a new instance of the LinqDataSourceValidationException class with serialized data.

LinqDataSourceValidationException(String) LinqDataSourceValidationException(String) LinqDataSourceValidationException(String) LinqDataSourceValidationException(String)

使用指定的描述错误的消息初始化 LinqDataSourceValidationException 类的新实例。Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error.

LinqDataSourceValidationException(String, Exception) LinqDataSourceValidationException(String, Exception) LinqDataSourceValidationException(String, Exception) LinqDataSourceValidationException(String, Exception)

使用指定的错误消息和对内部异常的引用来初始化 LinqDataSourceValidationException 类的新实例。Initializes a new instance of the LinqDataSourceValidationException class with a specified error message and a reference to the inner exception.

LinqDataSourceValidationException(String, IDictionary<String,Exception>) LinqDataSourceValidationException(String, IDictionary<String,Exception>) LinqDataSourceValidationException(String, IDictionary<String,Exception>) LinqDataSourceValidationException(String, IDictionary<String,Exception>)

使用描述错误的指定消息和对内部异常的引用集合来初始化 LinqDataSourceValidationException 类的新实例。Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error, and a collection of references to inner exceptions.

属性

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
InnerExceptions InnerExceptions InnerExceptions InnerExceptions

获取在验证新值或修改后的值期间发生的一个或多个异常。Gets one or more exceptions that occurred when new or modified data was being validated.

Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

获取关于异常的信息并将其添加到 SerializationInfo 对象。Gets information about the exception and adds it to the SerializationInfo object.

GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于