public override void Update() {
            var unitOfWork = new UnitOfWork(Session.DataLayer);

            if (unitOfWork.FindObject<PersistentAssemblyInfo>(null) != null)
                return;
            var persistentAssemblyInfo = new PersistentAssemblyInfo(unitOfWork){Name = "TestAssembly"};
            var persistentClassInfo = new PersistentClassInfo(unitOfWork){
                PersistentAssemblyInfo = persistentAssemblyInfo
            };
            persistentAssemblyInfo.PersistentClassInfos.Add(persistentClassInfo);
            persistentClassInfo.SetDefaultTemplate(TemplateType.Class);
            persistentClassInfo.Name = "TestClassInfo";
            persistentClassInfo.BaseType = typeof (Customer);
            persistentClassInfo.MergedObjectType = typeof (Customer);
            persistentClassInfo.TypeAttributes.Add(new PersistentDefaultClassOptionsAttribute(unitOfWork));
            persistentClassInfo.TypeAttributes.Add(new PersistentMapInheritanceAttribute(unitOfWork){
                MapInheritanceType = MapInheritanceType.ParentTable
            });
            var persistentCoreTypeMemberInfo = new PersistentCoreTypeMemberInfo(unitOfWork){
                DataType = DBColumnType.String,
                Name = "TestProp"
            };
            persistentClassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
            persistentCoreTypeMemberInfo.SetDefaultTemplate(TemplateType.ReadWriteMember);
            

            unitOfWork.CommitChanges();
        }
Esempio n. 2
0
        public override void Update(){
            if (Session.FindObject<PersistentAssemblyInfo>(info => info.Name == "OneToMany") == null) {
                var persistentAssemblyInfo = new PersistentAssemblyInfo(Session){Name = "OneToMany"};

                var projectCassInfo = new PersistentClassInfo(Session);
                persistentAssemblyInfo.PersistentClassInfos.Add(projectCassInfo);
                projectCassInfo.Name = "Project";
                projectCassInfo.SetDefaultTemplate(TemplateType.Class);
                projectCassInfo.TypeAttributes.Add(new PersistentDefaultClassOptionsAttribute(Session));
                
                var persistentCoreTypeMemberInfo = new PersistentCoreTypeMemberInfo(Session);
                projectCassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
                persistentCoreTypeMemberInfo.Name = "Name";
                persistentCoreTypeMemberInfo.DataType=DBColumnType.String;
                persistentCoreTypeMemberInfo.SetDefaultTemplate(TemplateType.ReadWriteMember);
                
                var contributorCassInfo = new PersistentClassInfo(Session);
                persistentAssemblyInfo.PersistentClassInfos.Add(contributorCassInfo);
                contributorCassInfo.Name = "Contributor";
                contributorCassInfo.SetDefaultTemplate(TemplateType.Class);

                persistentCoreTypeMemberInfo = new PersistentCoreTypeMemberInfo(Session);
                contributorCassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
                persistentCoreTypeMemberInfo.Name = "Name";
                persistentCoreTypeMemberInfo.DataType = DBColumnType.String;
                persistentCoreTypeMemberInfo.SetDefaultTemplate(TemplateType.ReadWriteMember);

                var collectionMemberInfo = new PersistentCollectionMemberInfo(Session);
                projectCassInfo.OwnMembers.Add(collectionMemberInfo);
                collectionMemberInfo.CollectionClassInfo = contributorCassInfo;
                collectionMemberInfo.Name = "Contributors";
                var associationAttribute = new PersistentAssociationAttribute(Session);
                collectionMemberInfo.TypeAttributes.Add(associationAttribute);
                associationAttribute.AssociationName = "Project-Contributors";
                collectionMemberInfo.SetDefaultTemplate(TemplateType.XPCollectionMember);

                var referenceMemberInfo = new PersistentReferenceMemberInfo(Session);
                contributorCassInfo.OwnMembers.Add(referenceMemberInfo);
                referenceMemberInfo.Name = "Project";
                referenceMemberInfo.ReferenceClassInfo = projectCassInfo;
                associationAttribute = new PersistentAssociationAttribute(Session);
                referenceMemberInfo.TypeAttributes.Add(associationAttribute);
                associationAttribute.AssociationName = "Project-Contributors";
                referenceMemberInfo.SetDefaultTemplate(TemplateType.ReadWriteMember);

//                ObjectSpace.CommitChanges();
            }

        }