Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net SubmitChanges不会更新数据库的外键_Vb.net_Linq_Silverlight_Windows Phone - Fatal编程技术网

Vb.net SubmitChanges不会更新数据库的外键

Vb.net SubmitChanges不会更新数据库的外键,vb.net,linq,silverlight,windows-phone,Vb.net,Linq,Silverlight,Windows Phone,我的问题发生在Windows Phone 8.1 Silverlight VB应用程序中。CatDataContext定义了一个带有项目标题和外键序列ID的表Books,它属于一个表系列 <Table()> Public Class Series Implements INotifyPropertyChanged, INotifyPropertyChanging ' Define ID: private field, public pro

我的问题发生在Windows Phone 8.1 Silverlight VB应用程序中。CatDataContext定义了一个带有项目标题和外键序列ID的表Books,它属于一个表系列

   <Table()>
    Public Class Series
        Implements INotifyPropertyChanged, INotifyPropertyChanging
        ' Define ID: private field, public property, and database column.
        Private _seriesID As Integer

        <Column(IsPrimaryKey:=True, IsDbGenerated:=True, DbType:="INT NOT NULL Identity", CanBeNull:=False,
            AutoSync:=AutoSync.OnInsert)>
        Public Property SeriesID() As Integer
            Get
                Return _seriesID
            End Get
            Set(ByVal value As Integer)
                If _seriesID <> value Then
                    NotifyPropertyChanging("SeriesID")
                    _seriesID = value
                    NotifyPropertyChanged("SeriesID")
                End If
            End Set
        End Property

        ' Define name: private field, public property, and database column.
        Private _Name As String
        <Column()>
        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                If _Name <> value Then
                    NotifyPropertyChanging("Name")
                    _Name = value
                    NotifyPropertyChanged("Name")
                End If
            End Set
        End Property

#Region "INotifyPropertyChanged Members"

        Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

        ' Used to notify that a property changed
        Private Sub NotifyPropertyChanged(ByVal propertyName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
        End Sub

#End Region

#Region "INotifyPropertyChanging Members"

        Public Event PropertyChanging As PropertyChangingEventHandler Implements INotifyPropertyChanging.PropertyChanging

        ' Used to notify that a property is about to change
        Private Sub NotifyPropertyChanging(ByVal propertyName As String)
            RaiseEvent PropertyChanging(Me, New PropertyChangingEventArgs(propertyName))
        End Sub

#End Region

    End Class

    <Table()>
    Public Class Book
        Implements INotifyPropertyChanged, INotifyPropertyChanging

        ' Define ID: private field, public property, and database column.
        Private _bookID As Integer
        <Column(IsPrimaryKey:=True, IsDbGenerated:=True, DbType:="INT NOT NULL Identity", CanBeNull:=False,
            AutoSync:=AutoSync.OnInsert)>
        Public Property BookID() As Integer
            Get
                Return _bookID
            End Get
            Set(ByVal value As Integer)
                If _bookID <> value Then
                    NotifyPropertyChanging("BookID")
                    _bookID = value
                    NotifyPropertyChanged("BookID")
                End If
            End Set
        End Property

        ' Define title: private field, public property, and database column.
        Private _title As String
        <Column()>
        Public Property Title() As String
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                If _title <> value Then
                    NotifyPropertyChanging("Title")
                    _title = value
                    NotifyPropertyChanged("Title")
                End If
            End Set
        End Property

        ' Internal column for the associated series ID value.
        <Column()>
        Friend _seriesID As Integer
        Private _series As EntityRef(Of Series)
        <Association(Storage:="_series", ThisKey:="_seriesID", OtherKey:="SeriesID")>
        Public Property BookSeries() As Series
            Get
                Return _series.Entity
            End Get
            Set(ByVal value As Series)
                NotifyPropertyChanging("BookSeries")
                _series.Entity = value
                If value IsNot Nothing Then
                    _seriesID = value.SeriesID
                End If
                NotifyPropertyChanged("BookSeries")
            End Set
        End Property

#Region "INotifyPropertyChanged Members"

        Public Event PropertyChanged As PropertyChangedEventHandler Implements NotifyPropertyChanged.PropertyChanged

        ' Used to notify that a property changed
        Private Sub NotifyPropertyChanged(ByVal propertyName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
        End Sub

#End Region

#Region "INotifyPropertyChanging Members"

        Public Event PropertyChanging As PropertyChangingEventHandler Implements INotifyPropertyChanging.PropertyChanging

        ' Used to notify that a property is about to change
        Private Sub NotifyPropertyChanging(ByVal propertyName As String)
            RaiseEvent PropertyChanging(Me, New PropertyChangingEventArgs(propertyName))
        End Sub

#End Region

公开课系列
实现INotifyPropertyChanged、INotifyPropertyChanged
'定义ID:私有字段、公共属性和数据库列。
Private _seriesID为整数
公共属性SeriesID()为整数
得到
返回序列ID
结束
设置(ByVal值为整数)
如果_seriesID值,则
NotifyPropertyChange(“SeriesID”)
_seriesID=值
NotifyPropertyChanged(“SeriesID”)
如果结束
端集
端属性
'定义名称:私有字段、公共属性和数据库列。
Private\u名称作为字符串
作为字符串的公共属性名()
得到
返回\u名称
结束
设置(ByVal值作为字符串)
如果_namevalue那么
NotifyPropertyChange(“名称”)
_名称=值
NotifyPropertyChanged(“名称”)
如果结束
端集
端属性
#区域“INotifyPropertyChanged成员”
公共事件PropertyChanged为PropertyChangedEventHandler实现INotifyPropertyChanged.PropertyChanged
'用于通知属性已更改
私有子NotifyPropertyChanged(ByVal propertyName作为字符串)
RaiseEvent PropertyChanged(Me,新PropertyChangedEventArgs(propertyName))
端接头
#末端区域
#区域“InotifyProperty更改成员”
公共事件PropertyChange作为PropertyChangeingEventHandler实现InotifyPropertyChange.PropertyChange
'用于通知属性即将更改
私有子NotifyPropertyChangeg(ByVal propertyName作为字符串)
RaiseEvent PropertyChange(Me,新PropertyChangeingEventArgs(propertyName))
端接头
#末端区域
末级
公共课堂用书
实现INotifyPropertyChanged、INotifyPropertyChanged
'定义ID:私有字段、公共属性和数据库列。
Private\u bookID为整数
公共属性BookID()为整数
得到
返回\u bookID
结束
设置(ByVal值为整数)
如果_bookID值,则
NotifyPropertyChange(“BookID”)
_bookID=值
NotifyPropertyChanged(“BookID”)
如果结束
端集
端属性
'定义标题:私有字段、公共属性和数据库列。
私有标题作为字符串
公共属性Title()作为字符串
得到
返回标题
结束
设置(ByVal值作为字符串)
如果_titlevalue那么
NotifyPropertyChange(“所有权”)
_标题=价值
NotifyPropertyChanged(“所有权”)
如果结束
端集
端属性
'关联系列ID值的内部列。
Friend\u seriesID为整数
私有_系列作为EntityRef(系列中的一个)

感谢您的关注。

\u seriesID
(在
书中
)只是一个成员变量。您可以从
书籍
外部设置它,因为它是
朋友
,但更进一步,什么也不会发生

另一方面,
Title
是激发
NotifyPropertyChanged
的属性。这意味着,如果您更改
标题
,则会通知上下文
书籍
对象已被修改

因此,如果您更改
\u seriesID
Title
,则
Book
对象将标记为已修改并已保存,同时更改
\u seriesID
的值。但是如果您单独更改
\u seriesID
,对象将保持“不变”


我认为这是生成的代码(LINQ到SQL?我真的不认识它),您不应该手动修改它。如果您想更改
\u seriesID
,您必须设置
BookSeries

请在问题中显示相关代码,而不是在单独的链接中。并适当注意代码格式和段落。您是否自己添加了
Friend\u seriesID
?我将其与Microsoft示例“如何使用MVVM为Windows Phone 8创建本地数据库应用程序”进行了类比。这是否回答了我的问题?我不确定,也许您应该重新编写您的问题,但我认为你的问题的简单答案是“是”。此外,在“私下”中改变“朋友”“使seriesID在项目的其余部分不可见。非常感谢您的努力,Gert。我将进一步探讨这一点,并在这个平台上让您知道。再次,我很高兴您的回答解释了为什么_seriesID不解雇NotifyPropertyChanged。我不知道如何采纳你的建议。BookSeries是另一张我不想换的桌子。我只想让Books中的_seriesID引用Bookseries表中的另一行。我现在只剩下以下可能性:1)每次_seriesID更改时,也会通过添加一个字符来更改标题,在SaveChangesToDB之后,标题将被恢复(我现在使用时没有问题)2)在CatDataContext中将_seriesID的定义更改为公共属性(而不是键)3)研究是否可以使用两个表的联接。直到现在,我还没有找到关于VB应用程序这个主题的有用信息。您只需执行类似于
book.BookSeries=series
的操作,其中
series
是一个
BookSeries
对象。这不会修改
BookSeries
对象本身。您的答案是这样的