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 を 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 に答える