public CrmAttribute(AttributeMetadata attribute, string entityName) { EntityName = entityName; Name = attribute.SchemaName; DisplayName = attribute?.DisplayName?.UserLocalizedLabel?.Label; SchemaName = attribute.SchemaName; if (attribute.AttributeType != null) { FieldType = attribute.AttributeType.Value; if (FieldType == AttributeTypeCode.Owner) { EntityReferenceLogicalName = "systemuser;team"; } else if (FieldType == AttributeTypeCode.Lookup || FieldType == AttributeTypeCode.Customer) { var lookup = (LookupAttributeMetadata)attribute; var value = string.Empty; foreach (var target in lookup.Targets) { value += target + ";"; } if (value.Length > 0) { value = value.Substring(0, value.Length - 1); } EntityReferenceLogicalName = value; } } IsCustomAttribute = attribute.IsCustomAttribute.Value; IsPrimaryKey = attribute.IsPrimaryId == true && entityName.ToLower() + "id" == Name.ToLower(); IsRequired = attribute.RequiredLevel != null && attribute.RequiredLevel.Value == AttributeRequiredLevel.ApplicationRequired; AttributeOf = attribute.AttributeOf; IsValidForCreate = attribute.IsValidForCreate ?? false; IsValidForRead = attribute.IsValidForRead ?? false; IsValidForUpdate = attribute.IsValidForUpdate ?? false; LogicalName = attribute.LogicalName; IsStateCode = attribute.AttributeType == AttributeTypeCode.State; DeprecatedVersion = attribute.DeprecatedVersion; IsDeprecated = !string.IsNullOrWhiteSpace(DeprecatedVersion); if (attribute.Description?.UserLocalizedLabel != null) { Description = attribute.Description.UserLocalizedLabel.Label; } Min = XrmHelper.GetMetadataMinValue(attribute); Max = XrmHelper.GetMetadataMaxValue(attribute); MaxLength = XrmHelper.GetMetadataMaxLengthValue(attribute); OptionSetValues = XrmHelper.GetMetadataOptionSetValues(attribute); DateTimeFormat = null; DateTimeBehavior = null; if (attribute is DateTimeAttributeMetadata dateAttribute) { try { DateTimeBehavior = dateAttribute.DateTimeBehavior; if (dateAttribute.Format != null) { DateTimeFormat = dateAttribute.Format.Value; } } catch { } } if (attribute is MultiSelectPicklistAttributeMetadata) { IsMultiSelectPicklist = true; } }