Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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 实体框架:从数据库更新模型时,Model.edmx修改丢失_Vb.net_Entity Framework_Edmx - Fatal编程技术网

Vb.net 实体框架:从数据库更新模型时,Model.edmx修改丢失

Vb.net 实体框架:从数据库更新模型时,Model.edmx修改丢失,vb.net,entity-framework,edmx,Vb.net,Entity Framework,Edmx,我首先使用实体框架和数据库,并从SQL server上的现有数据库创建了model.edmx。 现在出于某些原因,我对模型做了一些更改。 例如,我实现了InotiFyPropertyChanged,并且在一些类上更改了向导生成的原始代码。 但是,当我在数据库上更改某些内容时,我会从数据库更新模型,为实现上述功能所做的所有更改都会丢失,我必须从头开始编写所有更改。 当从数据库更新模型时,有没有办法保留这些更改? 或者另一种方法如何解决这个问题? 谢谢大家! 更新: Imports System I

我首先使用实体框架和数据库,并从SQL server上的现有数据库创建了model.edmx。 现在出于某些原因,我对模型做了一些更改。 例如,我实现了InotiFyPropertyChanged,并且在一些类上更改了向导生成的原始代码。 但是,当我在数据库上更改某些内容时,我会从数据库更新模型,为实现上述功能所做的所有更改都会丢失,我必须从头开始编写所有更改。 当从数据库更新模型时,有没有办法保留这些更改? 或者另一种方法如何解决这个问题? 谢谢大家!

更新:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports MyProg.MyObj1

   <MetadataType(GetType(MyObj1MetaData))> Partial Public Class Myobj1
Friend NotInheritable Class Myobj1MetaData
  Implements INotifyPropertyChanged
Private privatprc As Decimal
    Public Property prc() As Decimal
    Get
        Return privatprc
    End Get
    Set(ByVal value As Decimal)
        privatprc = value
        OnPropertyChanged("prc")
    End Set
End Property

Private privatcateg As Integer
    Public Property categ() As Integer
       Get
           Return privatcateg
        End Get
        Set(ByVal value As Integer)
            privatcateg = value
            OnPropertyChanged("categ")
        End Set
    End Property

 Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    Private Sub OnPropertyChanged(ByVal propertyc As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyc))
    End Sub
End Class
 End Class
这是向导生成的原始类:

Imports System
Imports System.Collections.Generic

Partial Public Class Myobj1
    Public Property id As Integer
    Public Property prc As Decimal
    Public Property categ As Integer
End Class
这是具有更改的类:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel

Partial Public Class Myobj1
    Implements INotifyPropertyChanged
    Public Property id As Integer

Private privatprc As Decimal
    Public Property prc() As Decimal
    Get
        Return privatprc
    End Get
    Set(ByVal value As Decimal)
        privatprc = value
        OnPropertyChanged("prc")
    End Set
End Property

Private privatcateg As Integer
    Public Property categ() As Integer
       Get
           Return privatcateg
        End Get
        Set(ByVal value As Integer)
            privatcateg = value
            OnPropertyChanged("categ")
        End Set
    End Property

 Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    Private Sub OnPropertyChanged(ByVal propertyc As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyc))
    End Sub
End Class
我该怎么办

更新: 我使用以下内容创建了一个单独的类文件:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports MyProg.MyObj1

   <MetadataType(GetType(MyObj1MetaData))> Partial Public Class Myobj1
Friend NotInheritable Class Myobj1MetaData
  Implements INotifyPropertyChanged
Private privatprc As Decimal
    Public Property prc() As Decimal
    Get
        Return privatprc
    End Get
    Set(ByVal value As Decimal)
        privatprc = value
        OnPropertyChanged("prc")
    End Set
End Property

Private privatcateg As Integer
    Public Property categ() As Integer
       Get
           Return privatcateg
        End Get
        Set(ByVal value As Integer)
            privatcateg = value
            OnPropertyChanged("categ")
        End Set
    End Property

 Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    Private Sub OnPropertyChanged(ByVal propertyc As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyc))
    End Sub
End Class
 End Class
导入系统
导入System.Collections.Generic
导入System.ComponentModel
导入MyProg.MyObj1
部分公共类Myobj1
友元不可继承类Myobj1MetaData
实现INotifyPropertyChanged
私有privatprc作为十进制
公共财产prc()为十进制
得到
返回privatprc
结束
设置(ByVal值为十进制)
privatprc=值
房地产变更(“中国”)
端集
端属性
作为整数的私有私钥
公共属性categ()为整数
得到
返回私家车
结束
设置(ByVal值为整数)
privatcateg=值
OnProperty变更(“类别”)
端集
端属性
公共事件PropertyChanged为PropertyChangedEventHandler实现INotifyPropertyChanged.PropertyChanged
私有子OnPropertyChanged(ByVal propertyc作为字符串)
RaiseEvent PropertyChanged(Me,新PropertyChangedEventArgs(propertyc))
端接头
末级
末级
一切运行都没有任何错误,但问题是我想要实现的特性(OnPropertyChanged)没有实现,而且这个新类似乎没有任何效果。 我能做什么? 谢谢大家!

查看此链接 你可能想看看ryanbesko的答案。分部类获取一个将其指向元数据类的属性。对不起,代码太乱了。我无法访问VS。这只是给你一个基本的想法:

<MetadataType(GetType(MyObj1Metadata))> 
    Public Partial Class MyObj1
    //your class code generated from ef goes here

    End Class
Public Class MyObj1Metadata

<Required(ErrorMessage := "Property is required.")> 
Private privatprc As Decimal
    Public Property prc() As Decimal
    Get
        Return privatprc
    End Get
    Set(ByVal value As Decimal)
        privatprc = value
        OnPropertyChanged("prc")
    End Set
End Property
// don't add any new code here, just match what is in your model classes and add data annotations to them.

End Class

公共部分类MyObj1
//从ef生成的类代码在这里
末级
公共类MyObj1Metadata
私有privatprc作为十进制
公共财产prc()为十进制
得到
返回privatprc
结束
设置(ByVal值为十进制)
privatprc=值
房地产变更(“中国”)
端集
端属性
//不要在这里添加任何新代码,只需匹配模型类中的内容并向它们添加数据注释即可。
末级
查看此链接 你可能想看看ryanbesko的答案。分部类获取一个将其指向元数据类的属性。对不起,代码太乱了。我无法访问VS。这只是给你一个基本的想法:

<MetadataType(GetType(MyObj1Metadata))> 
    Public Partial Class MyObj1
    //your class code generated from ef goes here

    End Class
Public Class MyObj1Metadata

<Required(ErrorMessage := "Property is required.")> 
Private privatprc As Decimal
    Public Property prc() As Decimal
    Get
        Return privatprc
    End Get
    Set(ByVal value As Decimal)
        privatprc = value
        OnPropertyChanged("prc")
    End Set
End Property
// don't add any new code here, just match what is in your model classes and add data annotations to them.

End Class

公共部分类MyObj1
//从ef生成的类代码在这里
末级
公共类MyObj1Metadata
私有privatprc作为十进制
公共财产prc()为十进制
得到
返回privatprc
结束
设置(ByVal值为十进制)
privatprc=值
房地产变更(“中国”)
端集
端属性
//不要在这里添加任何新代码,只需匹配模型类中的内容并向它们添加数据注释即可。
末级

关键是,一旦您更新模型,您对带有edmx文件的类所做的任何更改都将被删除。请您给我一些帮助,在我的特定情况下,在我的第一篇更新文章中,如何在链接上实现这一想法?非常感谢。此标记将位于分部类的上方。答案中没有出现。对不起,但两个类之间的联系是什么,因为公共类Myobj1Metadata似乎是一个与向导生成的类不相关的新类。没有访问Visual Studio的权限并不是不格式化代码的借口。关键是,在更新代码后,对带有edmx文件的类所做的任何更改都将被删除请问,你能给我一些帮助吗?在我的第一篇更新文章中,我如何在我的具体案例中实现这个想法?非常感谢。此标记将位于分部类的上方。答案中未显示。很抱歉,两个类之间的连接是什么,因为公共类Myobj1Metadata似乎是一个与向导生成的类无关的新类。无法访问Visual Studio不是不格式化代码的借口。