English 中文(简体)
在Billy 4 RIA(企业框架)中删除来自行的物体
原标题:Deleting object from DB in Silverlight 4 RIA (Entities framework)

I m developing simple Silverlight 4 application based on one-to-many association. The model of relation is presented here.

该网页由两个电网组成,一个是直装自域网(ExcelTemplate 1)。 在选择ExcelTemplate后,第二架装有可观测到的ColumnValidation Ruless,填在ExcelTemplate的名单上。 各实体没有采取行动。 我在删除ColumnValidation Rule目标家庭方面有很多问题。 基本上,我尝试了两种不同的做法:

  • Deleting only ColumnValidationRule using ColumnValidationRuleDomainDataSource (based on GetColumnValidationRule query):

<>XAML 缩略语

                                <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:ExcelTemplate, CreateList=true}" Height="0" LoadedData="ExcelTemplateDomainDataSource_LoadedData" Name="excelTemplatesForValidatiorsDDS" QueryName="GetExcelTemplatesQuery" Width="0">
                                    <riaControls:DomainDataSource.DomainContext>
                                        <my1:SRFDomainContext />
                                    </riaControls:DomainDataSource.DomainContext>
                                </riaControls:DomainDataSource>

                                <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:ColumnValidationRule, CreateList=true}" Height="0" LoadedData="ExcelTemplateDomainDataSource_LoadedData" Name="columnValidationRulesDomainDataSource" QueryName="GetColumnValidationRulesQuery" Width="0">
                                    <riaControls:DomainDataSource.DomainContext>
                                        <my1:SRFDomainContext />
                                    </riaControls:DomainDataSource.DomainContext>
                                </riaControls:DomainDataSource>

<><>Code>:

     // Filling DataViews:
     this.excelTemplatesForValidatiorsDDS.Load();
     this.columnValidationRulesDomainDataSource.Load();

    // Delete action:
    private void DeleteRuleButton_Click(object sender, RoutedEventArgs e)
    {
        this.columnValidationRulesDomainDataSource.Load();
        ColumnValidationRule cvr = this.srfValidatorsDataGrid.SelectedItem as ColumnValidationRule;
        this.columnValidationRulesDomainDataSource.DataView.Remove(cvr);
    }

In result im getting an error: The specified entity is not contained in this EntitySet.

www.un.org/Depts/DGACM/index_spanish.htm 错误细节:

w System.ServiceModel.DomainServices.Client.EntitySet.Remove(Entity entity)
   w System.Windows.Controls.PagedEntityCollectionView.RemoveCore(Entity item, Int32 index)
   w System.Windows.Controls.PagedEntityCollectionView.RemoveItem(Entity item)
   w System.Windows.Controls.EntityCollectionView.Remove(Object item)
   w System.Windows.Controls.DomainDataSourceView.Remove(Object item)
   w LANOS.UserManagement.DeleteRuleButton_Click(Object sender, RoutedEventArgs e)
   w System.Windows.Controls.Primitives.ButtonBase.OnClick()
   w System.Windows.Controls.Button.OnClick()
   w System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   w System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   w MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventN

  • Creating different DomainDataSource for each of objects family: ColumnValidationRule, AssociatedColumn, ColumnValue. Then deleting them using those DomainDataSource s and submitting from the tail to head. This approach also failed. I had similar error to those in 1st approach. Also from time to time some of those DomainDataSource s were empty.

我在举几个例子来说明这一问题,但我没有发现。 (a) 补偿任何倾斜、联系或帮助;


<>>><>>>>

我已利用你的建议:

    this.columnValidationRulesDomainDataSource.Load();
    ColumnValidationRule deletedObject = null;

    foreach (ColumnValidationRule cvr in this.columnValidationRulesDomainDataSource.DataView)
    {
        if (cvr.ID.Equals((this.srfValidatorsDataGrid.SelectedItem as ColumnValidationRule).ID))
        {
            deletedObject = cvr;
        }
    }
    this.columnValidationRulesDomainDataSource.DataView.Remove(deletedObject);
    this.columnValidationRulesDomainDataSource.SubmitChanges();

Now im getting this error: The item provided is not instance of type Entity :/


<><>>>

我在SubmitedChanges活动案手里加上了话,而且正如我在职位开始时怀疑的那样,外国钥匙造成的删除问题:

e.Error.Message "Submit operation failed. An error occurred while updating the entries. See the inner exception for details. InnerException message: The DELETE statement conflicted with the REFERENCE constraint "FK_AssociatedColumn_ColumnValidationRule". The conflict occurred in database "LANOS", table "dbo.AssociatedColumns", column  ColumnValidationRuleID .
The statement has been terminated."

Unfortunately I m not able to set up model to make use of End On Delete - Cascade property. Setting Cascade deleting cause compilation error:

End  ColumnValue  on relationship  LANOSModel.FK_AssociatedColumnColumnValue  cannot have operation specified since its multiplicity is  * . Operations cannot be specified on ends with multiplicity  * .
最佳回答

“实体名称”的理由是,......等到实体......该实体的指定instance ,在实体名称中,实际上不是。

你显然把数据网装上了以前的数据环境,而this.columnValidation RulessDomainDataSource.Load()则正在创建一套新的实体,因此你无法从新的数据集中删除其特定旧物体。 它们具有相同的价值,但不是相同的目标。

然而,你可以使用物体的钥匙,并在新情况下(如果该脂重合)删除。 只是首先发现对等,删除。

如果你能够提供更多细节/代码一,也许能够提供一个具体的例子,但现在你应该有足够的时间继续。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签