2011-12-09 113 views
3

使用示例代码在http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html我已经改变了这一点,以便GenerateEntity和GenerateOptionSet有代码:CRM 2011生成的代码使用ICodeWriterFilterService构建失败

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

这将生成类型,包括一些枚举了optionsets。在实体optionset的实际执行不但是用这个,但我得到以下几点:

[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在二传手不编译一个int,我认为它应该产生该属性的类型与生成的枚举相匹配,但不是。我需要做些什么来纠正这个问题?

+0

将这项解决方案的帮助? http://stackoverflow.com/a/8967568/1114306 –

回答

1

它看起来像crmsrvcutil已经修复了一个错误。我对OptionSet性质的代码现在看起来是这样的:

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

而且我没有得到任何错误设置OptionSetValue ...

+0

我使用的是最新版本crmsvcutil(5.0.9690.3218),并且为我的OptionSet属性生成的代码仍然以原始帖子的问题形式输出。 :/ – Polshgiant

+0

@Polshgiant考虑添加自己的问题。写在人们的评论中可能不会为你的特定问题找到答案。 – Daryl

+0

我只是注意到我对crmsvcutil最新版本的使用经历与您的不同。我最终使用上面链接的Guarav后的答案组合解决了这个问题。 – Polshgiant

相关问题