예제 #1
0
        private bool IsMetadataMissing(ImportData importData, out MissingMetadata result)
        {
            MetadataService metadataService = GetMetadataService();

            result = new MissingMetadata();

            foreach (IGrouping <string, DynamicEntity> group in importData.Entities.GroupBy(e => e.Name))
            {
                string entityName = group.Key;

                EntityMetadata entityMetadata = MetadataUtility.RetrieveEntityMetadata(metadataService, entityName);
                if (entityMetadata == null)
                {
                    result.MissingEntities.Add(entityName);
                }
                else
                {
                    IEnumerable <String> distinctAttributes = group
                                                              .SelectMany(e => e.Properties.Select(prop => prop.Name))
                                                              .Distinct();

                    List <string> missingAttributes =
                        distinctAttributes
                        .Except(entityMetadata.Attributes.Select(am => am.LogicalName))
                        .ToList();

                    if (missingAttributes.Count > 0)
                    {
                        result.AddMissingAttributes(entityName, missingAttributes);
                    }
                }
            }

            return(result.MissingEntities.Any() || result.MissingAttributes.Any());
        }
예제 #2
0
        private ColumnSet GetColumnsForExport(string entityName)
        {
            EntityMetadata entityMetadata = MetadataUtility.RetrieveEntityMetadata(_metadataService, entityName);

            var findValidColumnsQuery = from attribute in entityMetadata.Attributes
                                        where (attribute.ValidForCreate.Value && attribute.ValidForUpdate.Value && String.IsNullOrEmpty(attribute.AttributeOf)) ||
                                        attribute.LogicalName == "statecode"
                                        select attribute.LogicalName;

            return(new ColumnSet(findValidColumnsQuery.ToArray()));
        }