예제 #1
0
        public IEnumerable <MemberGeneratorInfo> Create()
        {
            var generatorInfos    = CreateMembersCore(GetNonCompoundPKColumns());
            var coumboundPkColumn = GetCoumboundPKColumn();

            if (coumboundPkColumn != null)
            {
                string tableName           = ClassGenerator.GetTableName(_dbTable.Name);
                var    persistentClassInfo = _classInfos[tableName + ClassGenerator.KeyStruct].PersistentClassInfo;
                if (persistentClassInfo == null)
                {
                    throw new ArgumentNullException("persistentClassInfo with name " + _dbTable.Name + ClassGenerator.KeyStruct);
                }
                var pkDbColumns = coumboundPkColumn.Columns.OfType <string>().Select(s => _dbTable.GetColumn(s));
                var membersCore = CreateMembersCore(pkDbColumns, persistentClassInfo, TemplateType.ReadWriteMember, TemplateType.ReadWriteMember).ToList();
                var persistentReferenceMemberInfo = CreatePersistentReferenceMemberInfo(persistentClassInfo.Name, _classInfos[tableName].PersistentClassInfo, persistentClassInfo, TemplateType.FieldMember);
                membersCore.Add(new MemberGeneratorInfo(persistentReferenceMemberInfo, _dbTable.GetColumn(coumboundPkColumn.Columns[0])));
                if (pkDbColumns.Where(IsOneToOneOnTheKey).Count() == pkDbColumns.Count())
                {
                    string             refTableName       = ClassGenerator.GetTableName(_dbTable.ForeignKeys.First(key => key.Columns.Contains(pkDbColumns.ToList()[0].Name)).PrimaryKeyTable);
                    ClassGeneratorInfo classGeneratorInfo = _classInfos[refTableName];
                    membersCore.Add(new MemberGeneratorInfo(CreatePersistentReferenceMemberInfo(classGeneratorInfo.PersistentClassInfo.Name, _classInfos[tableName].PersistentClassInfo, classGeneratorInfo.PersistentClassInfo, TemplateType.XPOneToOneReadOnlyPropertyMember), null));
                }
                return(generatorInfos.Union(membersCore));
            }
            return(generatorInfos);
        }
예제 #2
0
 public MemberAttributeGenerator(MemberGeneratorInfo memberGeneratorInfo, ClassGeneratorInfo classGeneratorInfo) {
     _objectSpace = XPObjectSpace.FindObjectSpaceByObject(memberGeneratorInfo.PersistentMemberInfo);
     _persistentMemberInfo = memberGeneratorInfo.PersistentMemberInfo;
     _column = memberGeneratorInfo.DbColumn;
     _isPrimaryKey = CalculatePrimaryKey(memberGeneratorInfo, classGeneratorInfo);
     _dbTable = classGeneratorInfo.DbTable;
 }
예제 #3
0
 public ClassAtrributeGenerator(ClassGeneratorInfo classGeneratorInfo, string navigationPath)
 {
     _persistentClassInfo = classGeneratorInfo.PersistentClassInfo;
     _dbTable             = classGeneratorInfo.DbTable;
     _navigationPath      = navigationPath;
     _objectSpace         = XPObjectSpace.FindObjectSpaceByObject(_persistentClassInfo);
 }
예제 #4
0
 bool CalculatePrimaryKey(MemberGeneratorInfo memberGeneratorInfo, ClassGeneratorInfo classGeneratorInfo)
 {
     if (classGeneratorInfo.DbTable.PrimaryKey != null && memberGeneratorInfo.DbColumn != null)
     {
         return(classGeneratorInfo.DbTable.PrimaryKey.Columns.Contains(memberGeneratorInfo.DbColumn.Name));
     }
     return(false);
 }
예제 #5
0
 public MemberAttributeGenerator(MemberGeneratorInfo memberGeneratorInfo, ClassGeneratorInfo classGeneratorInfo)
 {
     _objectSpace          = XPObjectSpace.FindObjectSpaceByObject(memberGeneratorInfo.PersistentMemberInfo);
     _persistentMemberInfo = memberGeneratorInfo.PersistentMemberInfo;
     _column       = memberGeneratorInfo.DbColumn;
     _isPrimaryKey = CalculatePrimaryKey(memberGeneratorInfo, classGeneratorInfo);
     _dbTable      = classGeneratorInfo.DbTable;
 }
예제 #6
0
 public ClassGeneratorHelper(IObjectSpace XPObjectSpace) {
     _persistentAssemblyInfo = XPObjectSpace.CreateObject<PersistentAssemblyInfo>();
     _persistentAssemblyInfo.Name = "PersistentAssemblyInfo";
     _persistentClassInfo = XPObjectSpace.CreateObject<PersistentClassInfo>();
     _persistentClassInfo.Name = "MainTable";
     _persistentAssemblyInfo.PersistentClassInfos.Add(_persistentClassInfo);
     _persistentClassInfo.SetDefaultTemplate(TemplateType.Class);
     _classGeneratorInfos = new Dictionary<string, ClassGeneratorInfo>();
     var classGeneratorInfo = new ClassGeneratorInfo(PersistentClassInfo, DbTable);
     _classGeneratorInfos.Add(PersistentClassInfo.Name, classGeneratorInfo);
 }
예제 #7
0
        TemplateType GetTemplateType(TemplateType refTemplateType, ClassGeneratorInfo classGeneratorInfo)
        {
            bool selfReference = classGeneratorInfo.DbTable.Name == _dbTable.Name;

            if (!selfReference)
            {
                DBForeignKey oneToOne = classGeneratorInfo.DbTable.ForeignKeys.FirstOrDefault(key => key.PrimaryKeyTable == _dbTable.Name);
                if (oneToOne != null)
                {
                    return(TemplateType.XPOneToOnePropertyMember);
                }
            }
            return(refTemplateType);
        }
예제 #8
0
 bool CalculatePrimaryKey(MemberGeneratorInfo memberGeneratorInfo, ClassGeneratorInfo classGeneratorInfo) {
     if (classGeneratorInfo.DbTable.PrimaryKey != null && memberGeneratorInfo.DbColumn != null)
         return classGeneratorInfo.DbTable.PrimaryKey.Columns.Contains(memberGeneratorInfo.DbColumn.Name);
     return false;
 }
예제 #9
0
 public ClassAtrributeGenerator(ClassGeneratorInfo classGeneratorInfo, string navigationPath) {
     _persistentClassInfo = classGeneratorInfo.PersistentClassInfo;
     _dbTable = classGeneratorInfo.DbTable;
     _navigationPath = navigationPath;
     _objectSpace = XPObjectSpace.FindObjectSpaceByObject(_persistentClassInfo);
 }
예제 #10
0
 TemplateType GetTemplateType(TemplateType refTemplateType, ClassGeneratorInfo classGeneratorInfo) {
     bool selfReference = classGeneratorInfo.DbTable.Name == _dbTable.Name;
     if (!selfReference) {
         DBForeignKey oneToOne = classGeneratorInfo.DbTable.ForeignKeys.FirstOrDefault(key => key.PrimaryKeyTable == _dbTable.Name);
         if (oneToOne != null)
             return TemplateType.XPOneToOnePropertyMember;
     }
     return refTemplateType;
 }