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
Entity framework 限制在Silverlight中更新实体数据模型中的字段_Entity Framework_Silverlight 5.0_Wcf Ria Services - Fatal编程技术网

Entity framework 限制在Silverlight中更新实体数据模型中的字段

Entity framework 限制在Silverlight中更新实体数据模型中的字段,entity-framework,silverlight-5.0,wcf-ria-services,Entity Framework,Silverlight 5.0,Wcf Ria Services,我在数据库中有一个字段“IsActive”,默认为“Null”。现在我想更新字段一次并将其设置为true。现在,一旦该字段设置为true,我需要禁止对其进行进一步修改。请帮忙 对于RIA Services在实体中创建的每个属性,RIA Services也会创建几个部分方法存根,当属性值发生更改以供您覆盖时,会调用这些存根,例如,对于iActive属性,RIA Services会生成: Private Partial Sub OnIsActiveChanging(ByVal value A

我在数据库中有一个字段“IsActive”,默认为“Null”。现在我想更新字段一次并将其设置为true。现在,一旦该字段设置为true,我需要禁止对其进行进一步修改。请帮忙

对于RIA Services在实体中创建的每个属性,RIA Services也会创建几个部分方法存根,当属性值发生更改以供您覆盖时,会调用这些存根,例如,对于iActive属性,RIA Services会生成:

    Private Partial Sub OnIsActiveChanging(ByVal value As Boolean)
    End Sub

    Private Partial Sub OnIsActiveChanged()
    End Sub
您将在RIA服务在编译时创建的文件中找到这些存根(在Silverlight项目文件夹中的Generated_Code文件夹中;它不会包含在项目本身中)

没有办法“取消”更改,但您可以自己添加一些逻辑来设置值,例如,在实体的分部类中:

    Private _setBackToTrue As Boolean

    Private Sub OnIsActiveChanging(ByVal value As Boolean)
        If Not value AndAlso Me.IsActive Then
            _setBackToTrue = True
        End If
    End Sub

    Private Sub OnIsActiveChanged()
        If _setBackToTrue Then
            Me.IsActive = True
            _setBackToTrue = False
        End If
    End Sub