使用http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html上的示例代码我已经改变了这个,以便 GenerateEntity 和 GenerateOptionSet 有代码:
return optionSetMetadata.Name.ToLowerInvariant().StartsWith("myprefix");
这会生成包括选项集的一些枚举的类型。但是,实体中选项集的实际实现不使用它,但我得到以下信息:
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("myprefix_fieldname")]
public Microsoft.Xrm.Sdk.OptionSetValue myprefix_FieldName
{
get
{
Microsoft.Xrm.Sdk.OptionSetValue optionSet = this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("myprefix_fieldname");
if ((optionSet != null))
{
return ((Microsoft.Xrm.Sdk.OptionSetValue)(System.Enum.ToObject(typeof(Microsoft.Xrm.Sdk.OptionSetValue), optionSet.Value)));
}
else
{
return null;
}
}
set
{
this.OnPropertyChanging("myprefix_FieldName");
if ((value == null))
{
this.SetAttributeValue("myprefix_fieldname", null);
}
else
{
this.SetAttributeValue("myprefix_fieldname", new Microsoft.Xrm.Sdk.OptionSetValue(((int)(value))));
}
this.OnPropertyChanged("myprefix_FieldName");
}
}
显然,将 OptionSetValue 转换为 setter 中的 int 不会编译,我假设它应该生成与生成的枚举匹配的类型的属性,但不是。我需要做什么来纠正这个问题?