Пример #1
0
        public ModelDefinition(Type bindingType)
        {
            BindingType           = bindingType;
            ImplementedInterfaces = bindingType.GetInterfaces();

            IsBindingModel = typeof(IBindingModel).IsAssignableFrom(bindingType);

            Constructor = bindingType.GetConstructor(new Type[] { });
            if (Constructor == null)
            {
                throw new Exception("No default Constructor found");
            }

            if (IsBindingModel)
            {
                IdProperty     = bindingType.GetProperty("Id");
                MainDefinition = DefinitionCache.GetEntityDefinition(bindingType);
            }

            XmlMappingAttribute = bindingType.GetCustomAttribute <XmlMappingAttribute>() ??
                                  ImplementedInterfaces.Where(type => type.GetCustomAttribute <XmlMappingAttribute>() != null).Select(type => type.GetCustomAttribute <XmlMappingAttribute>()).FirstOrDefault();

            foreach (var property in bindingType.GetProperties())
            {
                var attribute = AttributeDefinition.GetDefinition(this, property);

                _attributes.Add(attribute);
            }
        }
Пример #2
0
        private static bool CanBeRemoved(LinkEntity link)
        {
            var targetDefinition = DefinitionCache.GetEntityDefinition(link.LinkToEntityName);

            var hasNoLinkAndNoCriteria = !link.LinkEntities.Any() && !HasConditions(link.LinkCriteria) && !link.LinkCriteria.Filters.Any();

            var hasOnlyPrimaryField = link.Columns.Columns.All(attribute => attribute == targetDefinition.PrimaryIdAttributeName || attribute == targetDefinition.PrimaryNameAttributeName);

            return(hasNoLinkAndNoCriteria && hasOnlyPrimaryField);
        }
Пример #3
0
        //public Relationship GetRelationshipFromAttributeName(string attributeName)
        //{
        //    return GetRelationshipsFromAttributeName(attributeName).FirstOrDefault();
        //}

        public EntityDefinition GetSubDefinition(string attributeName, string entityName = null)
        {
            var lookupAttributes = GetCrmLookupAttributes(attributeName);

            var lookupAttribute = lookupAttributes.FirstOrDefault(l => string.IsNullOrEmpty(entityName) || l.TargetEntityName == entityName);

            if (lookupAttribute == null)
            {
                throw new KeyNotFoundException($"Attribute {attributeName} is not a lookup to the {entityName} entity.");
            }

            return(DefinitionCache.GetEntityDefinition(lookupAttribute.TargetEntityName));
        }