Exemple #1
0
        private void CreateRelation(string primaryClassName, string relatedClassName)
        {
            MetaClass relatedMetaClass = DataContext.Current.GetMetaClass(relatedClassName);
            MetaClass primaryMetaClass = DataContext.Current.GetMetaClass(primaryClassName);

            if (relatedMetaClass.Fields[MetaClassManager.GetPrimaryKeyName(primaryClassName)] != null)
            {
                return;
            }
            using (MetaClassManagerEditScope managerEditScope = DataContext.Current.MetaModel.BeginEdit())
            {
                var metaField = relatedMetaClass.CreateReference(primaryMetaClass, primaryClassName, primaryClassName, true);
                metaField.AccessLevel = AccessLevel.Customization;

                metaField.Attributes.Add(Constants.Attributes.DisplayBlock, Constants.SectionName);
                metaField.Attributes.Add(Constants.Attributes.DisplayText, relatedClassName);
                metaField.Attributes.Add(Constants.Attributes.DisplayOrder, Constants.DefaultDisplayOrder);
                XmlBuilder.ClearCache();

                managerEditScope.SaveChanges();
            }
        }