private AddForeignKeyResult AddAllForeignKeys(DatabaseAgent agent, Assembly daoAssembly, string contextName) { List <DaoForeignKeyInfo> foreignKeys = new List <DaoForeignKeyInfo>(); foreach (Type type in daoAssembly.GetTypes()) { object[] tableAttributes = type.GetCustomAttributes(typeof(DaoTable), false); if (tableAttributes.Length == 1) { DaoTable tableAttribute = (DaoTable)tableAttributes[0]; ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes); DaoObject obj = (DaoObject)ctor.Invoke(null); if (obj.DataContextName.Equals(contextName)) { foreignKeys.AddRange(this.GetForeignKeys(obj, tableAttribute.TableName)); } } } AddForeignKeyResult retVal = AddForeignKeyResult.Success; foreach (DaoForeignKeyInfo foreignKey in foreignKeys) { if (this.AddForeignKey(foreignKey, agent) == AddForeignKeyResult.Error) { retVal = AddForeignKeyResult.Error; } } return(retVal); }
public AddForeignKeyResult AddAllForeignKeys <T>(DatabaseAgent agent) where T : DaoObject, new() { Assembly daoAssembly = typeof(T).Assembly; string contextName = new T().DataContextName; AddForeignKeyResult retVal = AddAllForeignKeys(agent, daoAssembly, contextName); return(retVal); }