Я пытаюсь обновить запись в таблице учеников, используя LINQ to SQL. Проблема заключается в том, что одно из свойств объекта изменилось, и событие ' PropertyChanging ' вызывается с использованием метода ' SendPropertyChanging () '.
Обратите внимание:
- student_id - это PK
- типы данных совпадают
Вот полное исключение ArgumentException:
GenericArguments [2], 'System.String', вкл
'System.Data.Linq.Mapping.PropertyAccessor + Accessor`3 [Т, V, V2]
нарушает ограничение типа 'V2'.
Stack Strace
в System.RuntimeType.ValidateGenericArguments (MemberInfo
определение, RuntimeType [] genericArguments, исключение e) в
System.RuntimeType.MakeGenericType (Type [] instantiation) в
System.Data.Linq.Mapping.PropertyAccessor.Create (Тип objectType,
PropertyInfo pi, MetaAccessor storageAccessor) в
System.Data.Linq.Mapping.AttributedMetaDataMember.MakeMemberAccessor (Тип
accessorType, MemberInfo mi, хранилище MetaAccessor) в
System.Data.Linq.Mapping.AttributedMetaDataMember.InitAccessors ()
в
System.Data.Linq.Mapping.AttributedMetaDataMember.get_StorageAccessor ()
в
System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackedObject.CreateDataCopy (Объект
экземпляр) в
System.Data.Linq.ChangeTracker.StandardChangeTracker.OnPropertyChanging (Объект
отправитель, PropertyChangingEventArgs args) в
pro.Student.SendPropertyChanging () в
C: \ inetpub \ wwwroot \ pro \ Models \ Student.vb: строка 384 в
pro.Student.set_first_name (строковое значение) в
C: \ inetpub \ wwwroot \ pro \ Models \ Student.vb: строка 132 в
pro.WizardController.SetLanguageAndText (LanguageAndTextInfo ltInfo) в
C: \ inetpub \ wwwroot \ pro \ Controllers \ WizardController.vb: строка 517 в
lambda_method (Closure, ControllerBase, Object []) в
System.Web.Mvc.ActionMethodDispatcher.Execute (ControllerBase
контроллер, параметры Object []) в
System.Web.Mvc.ReflectedActionDescriptor.Execute (ControllerContext
controllerContext, IDictionary 2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary
2
параметры) при
System.Web.Mvc.ControllerActionInvoker. <> C_ DisplayClass15.b _12 ()
в
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (IActionFilter
фильтр, ActionExecutingContext preContext, продолжение Func`1)
Вот класс Student.vb:
Imports Microsoft.VisualBasic
Imports System.Xml.Serialization
Imports System.IO
Imports System.Data.Linq.Mapping
Imports System.ComponentModel
<Global.System.Data.Linq.Mapping.TableAttribute(name:="dbo.Students")> _
Public Class Student
Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
Private _student_id As System.Guid
Private _first_name As String
Private _last_name As String
Private _email As String
Public Sub New()
End Sub
#Region "Properties"
<Global.System.Data.Linq.Mapping.ColumnAttribute(name:="student_id", Storage:="_student_id", DbType:="uniqueidentifier NOT NULL", IsPrimaryKey:=True, IsDbGenerated:=True, CanBeNull:=False)> _
Public Property student_id() As System.Guid
Get
Return _student_id
End Get
Set(value As System.Guid)
If ((_student_id = value) = False) Then
SendPropertyChanging()
_student_id = value
SendPropertyChanged("student_id")
End If
End Set
End Property
<Global.System.Data.Linq.Mapping.ColumnAttribute(name:="first_name", Storage:="_first_name", DbType:="nvarchar(250) NOT NULL", CanBeNull:=False)> _
Public Property first_name() As String
Get
Return _first_name
End Get
Set(ByVal value As String)
If ((_first_name = value) = False) Then
**SendPropertyChanging()**
_first_name = value
SendPropertyChanged("first_name")
End If
End Set
End Property
<Global.System.Data.Linq.Mapping.ColumnAttribute(name:="last_name", Storage:="_last_name", DbType:="nvarchar(250) NOT NULL", CanBeNull:=False)> _
Public Property language() As String
Get
Return _last_name
End Get
Set(ByVal value As String)
If ((_last_name = value) = False) Then
**SendPropertyChanging()**
_last_name = value
SendPropertyChanged("last_name")
End If
End Set
End Property
<Global.System.Data.Linq.Mapping.ColumnAttribute(name:="email", Storage:="_email", DbType:="nvarchar(250) NOT NULL", CanBeNull:=False)> _
Public Property email() As String
Get
Return _email
End Get
Set(ByVal value As String)
If ((_email = value) = False) Then
**SendPropertyChanging()**
_email = value
SendPropertyChanged("email")
End If
End Set
End Property
#End Region
#Region "Linq Methods"
Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging
Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub SendPropertyChanging()
If ((Me.PropertyChangingEvent Is Nothing) = False) Then
RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
End If
End Sub
Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
If ((Me.PropertyChangedEvent Is Nothing) = False) Then
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End If
End Sub
#End Region
End Class
Вот так я пытаюсь обновить Студента
Using context As New dbStudents(strConnString)
Dim tmpStudent = (From p In context.Students
Where p.student_id = CurStudent.student_id
Select p).FirstOrDefault()
tmpStudent.FirstName = CurStudent.FirstName
tmpStudent.LastName = CurStudent.LastName
tmpStudent.Email = CurStudent.Email
context.SubmitChanges()
End Using
Спасибо!