我有一个类,它采用标准的地址属性并存储它们.State属性的类型为USStateCodesType.以下是用于存储属性的代码示例:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://SP/Items/Schemas")]
public partial class BusinessAddress
{
private string address1Field;
private string address2Field;
private string cityField;
private USStateCodesType stateField;
private bool stateFieldSpecified;
private string zipField;
/// <remarks/>
public string Address1
{
get
{
return this.address1Field;
}
set
{
this.address1Field = value;
}
}
Run Code Online (Sandbox Code Playgroud)
USStateCodesType包含带字符串键和值的私有字典.默认构造函数加载字典并由任何重载调用.国家只有一个公共财产.编码如下:
public string State
{
get
{
return iDict[_key];
}
set
{
if (iDict.ContainsValue(value))
{
foreach (string k in iDict.Keys)
if (iDict[k] == value)
_key = k;
}
else
_key = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试更新资源,如下所示:
public void Update(Resource resource) {
Resource _resource = _resourceRepository.First(r => r.Id == resource.Id);
_resource.Content = resource.Content;
_resource.Description = resource.Description;
_resource.Locked = resource.Locked;
_resource.Name = resource.Name;
_resource.Restrictions.ToList().ForEach(r => _resource.Restrictions.Remove(r));
foreach (Restriction restriction in resource.Restrictions)
_resource.Restrictions.Add(new Restriction { Property = _propertyRepository.First(p => p.Id == restriction.Property.Id), Value = restriction.Value });
} // Update
Run Code Online (Sandbox Code Playgroud)
我有一些类似的工作,创建一个只有一个区别的资源:我没有删除限制.
我收到以下错误:
来自'Restrictions_ResourceId_FK'AssociationSet的关系处于'已删除'状态.给定多重约束,相应的"限制"也必须处于"已删除"状态.
我错过了什么?