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); }
public MemberAttributeGenerator(MemberGeneratorInfo memberGeneratorInfo, ClassGeneratorInfo classGeneratorInfo) { _objectSpace = XPObjectSpace.FindObjectSpaceByObject(memberGeneratorInfo.PersistentMemberInfo); _persistentMemberInfo = memberGeneratorInfo.PersistentMemberInfo; _column = memberGeneratorInfo.DbColumn; _isPrimaryKey = CalculatePrimaryKey(memberGeneratorInfo, classGeneratorInfo); _dbTable = classGeneratorInfo.DbTable; }
public ClassAtrributeGenerator(ClassGeneratorInfo classGeneratorInfo, string navigationPath) { _persistentClassInfo = classGeneratorInfo.PersistentClassInfo; _dbTable = classGeneratorInfo.DbTable; _navigationPath = navigationPath; _objectSpace = XPObjectSpace.FindObjectSpaceByObject(_persistentClassInfo); }
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); }
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); }
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); }
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; }
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; }