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,填在
- 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 * .