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