示例#1
0
 private List<AssociationModel> BuildAssociations(DAL dal)
 {
     var associations = new List<AssociationModel>();
     foreach (var rawAssociation in dal.GetRawAssociations())
     {
         var association = new AssociationModel();
         association.PrimaryTable = db.Tables.Single(t => t.Name.Equals(rawAssociation.Item2));
         association.ForeignTable = db.Tables.Single(t => t.Name.Equals(rawAssociation.Item1));
         association.PrimaryColumn = association.PrimaryTable.Columns.Single(c => c.Name.EqualsIgnoreCase(dal.GetPrimaryColumnName(association)));
         association.ForeignColumn = association.ForeignTable.Columns.Single(c => c.Name.EqualsIgnoreCase(dal.GetForeignColumnName(association)));
         association.ForeignTable.ForeignKeys.Add(association.ForeignColumn);
         association.Type = AssociationType.OneToMany;
         associations.Add(association);
     }
     return associations;
 }
示例#2
0
 private void SetPrimaryKeys()
 {
     using (var dal = new DAL(connectionString))
     {
         foreach (var table in db.Tables)
         {
             string pColumnName = dal.GetPrimaryColumnName(table);
             table.PrimaryKey = table.Columns.Single(c => c.Name.EqualsIgnoreCase(pColumnName));
         }
     }
 }