private static List <LookupListItem <Guid?> > GetLookupValues(bool withEmptyRow, EntityAttribute attribute)
        {
            var    lookupValue       = attribute.AttributeLookupValues.First();
            var    lookupValueEntity = lookupValue.Entity;
            string displayMemberName =
                lookupValueEntity.Attributes.First(a => a.AttributeId == lookupValue.DisplayEntityAttributeId).PhysicalName;
            string valueMemberName = lookupValueEntity.Name + "Id";
            var    values          = new DynamicDataServiceContext().GetObjects(lookupValueEntity.PhysicalName);

            var items = new List <LookupListItem <Guid?> >();

            foreach (var value in values)
            {
                var    item        = new LookupListItem <Guid?>();
                object displayName = value.GetType().GetProperty(displayMemberName).GetValue(value, null);
                if (displayName != null)
                {
                    item.DisplayName = displayName.ToString();
                    item.Value       = (Guid)value.GetType().GetProperty(valueMemberName).GetValue(value, null);
                    items.Add(item);
                }
            }
            if (withEmptyRow)
            {
                items.Insert(0, new LookupListItem <Guid?>());
            }
            return(items);
        }
        private static List <LookupListItem <int?> > GetPickListValues(EntityAttribute attribute, int langId)
        {
            var values = attribute.OptionSet.AttributePicklistValues.OrderBy(v => v.DisplayOrder);
            var items  = new List <LookupListItem <int?> >();
            var labels = MetadataProvider.Instance.LocalizedLabels;

            foreach (var value in values)
            {
                var item            = new LookupListItem <int?>();
                var localizedLabels = labels.Where(l => l.ObjectId == value.AttributePicklistValueId);
                var localizedLabel  = localizedLabels.FirstOrDefault(l => l.LanguageId == langId) ?? localizedLabels.First();
                if (localizedLabel != null)
                {
                    item.DisplayName = localizedLabel.Label;
                }
                item.Value = value.Value;
                items.Add(item);
            }
            if (attribute.IsNullable.HasValue && attribute.IsNullable.Value)
            {
                items.Insert(0, new LookupListItem <int?>());
            }
            return(items);
        }