3

使用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 不会编译,我假设它应该生成与生成的枚举匹配的类型的属性,但不是。我需要做什么来纠正这个问题?

4

1 回答 1

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 没有错误...

于 2012-11-01T13:21:14.610 回答