CRM 2011使用ICodeWriterFilterService生成的代码无法构建

使用http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html上的示例代码,我已对此进行了更改,以便GenerateEntity和GenerateOptionSet具有以下代码:

return optionSetMetadata.Name.ToLowerInvariant().StartsWith("myprefix");

这将生成类型,包括选项集的一些枚举。 然而,实体中的optionset的实际实现并没有使用它,但我得到以下内容:

  [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("myprefix_fieldname")] public Microsoft.Xrm.Sdk.OptionSetValue myprefix_FieldName { get { Microsoft.Xrm.Sdk.OptionSetValue optionSet = this.GetAttributeValue("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"); } } 

显然,将setSetValue转换为setter中的int不会编译,我假设它应该生成一个类型与生成的枚举匹配的属性,但不是。 我需要做些什么才能纠正这个问题?

看起来crmsrvcutil中有一个错误已被修复。 我的OptionSet属性代码现在看起来像这样:

 [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("prioritycode")] public Microsoft.Xrm.Sdk.OptionSetValue PriorityCode { get { return this.GetAttributeValue("prioritycode"); } set { this.OnPropertyChanging("PriorityCode"); this.SetAttributeValue("prioritycode", value); this.OnPropertyChanged("PriorityCode"); } } 

我没有设置OptionSetValue的错误…