using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
/// <summary>
/// String
/// </summary>
public class CreateStringAttribute
{
private string entityName = "new_class";
public void Create(IOrganizationService service)
{
CreateAttributeRequest request = new CreateAttributeRequest();
//关联的实体名称
request.EntityName = entityName;
StringAttributeMetadata stringAttr = new StringAttributeMetadata();
//字段名称
stringAttr.LogicalName = "new_stringvalue";
//架构名称
stringAttr.SchemaName = "new_stringvalue";
//显示中文名称
stringAttr.DisplayName = new Label("String字段",2052);
//字段的最大长度
stringAttr.MaxLength = 300;
//需求级别
stringAttr.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
//字段安全性
stringAttr.IsSecured = false;
//审核
stringAttr.IsAuditEnabled = new BooleanManagedProperty(false);
request.Attribute = stringAttr;
service.Execute(request);
System.Console.WriteLine("创建成功!");
}
}