// The logic that figures out the association is not yet ready. For now we use the second implementation, which // gets us going until we iron things out #if NOTYETREADY internal void Initialize() { if (DataServiceUtilities.IsEntityType(this.ColumnType, this.Table.DataModel.ContextType)) { TableProvider tp = this.Table.DataModel.Tables .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType)); if (tp != null) { DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(tp) { ColumnType = typeof(string), Name = "Null(" + this.Table.Name + "." + this.Name + ")" }; ((DataServiceTableProvider)tp).AddColumn(nullColumn); Association = new DataServiceAssociationProvider( AssociationDirection.ManyToOne, this, nullColumn, new List <string>() { this.Table.Name + "({0})/" + this.Name }); } } // not the best heuristic, but it'll do for now else if (!DataServiceUtilities.IsPrimitiveType(this.ColumnType) && typeof(IEnumerable).IsAssignableFrom(this.ColumnType) && this.ColumnType.GetGenericArguments().Length > 0 && DataServiceUtilities.IsEntityType(this.ColumnType.GetGenericArguments()[0], this.Table.DataModel.ContextType)) { TableProvider tp = this.Table.DataModel.Tables .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType)); if (tp != null) { DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(this.Table) { ColumnType = typeof(string), Name = "Null(" + this.Table.Name + "." + this.Name + ")" }; ((DataServiceTableProvider)tp).AddColumn(nullColumn); Association = new DataServiceAssociationProvider( AssociationDirection.ManyToMany, this, nullColumn, new List <string>() { this.Table.Name + "({0})/" + this.Name }); } } }
// The logic that figures out the association is not yet ready. For now we use the second implementation, which // gets us going until we iron things out internal void Initialize() { if (DataServiceUtilities.IsEntityType(this.ColumnType, this.Table.DataModel.ContextType)) { TableProvider tp = this.Table.DataModel.Tables .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType)); if (tp != null) { DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(tp) { ColumnType = typeof(string), Name = "Null(" + this.Table.Name + "." + this.Name + ")" }; ((DataServiceTableProvider)tp).AddColumn(nullColumn); Association = new DataServiceAssociationProvider( AssociationDirection.ManyToOne, this, nullColumn, new List<string>() { this.Table.Name + "({0})/" + this.Name }); } } // not the best heuristic, but it'll do for now else if (!DataServiceUtilities.IsPrimitiveType(this.ColumnType) && typeof(IEnumerable).IsAssignableFrom(this.ColumnType) && this.ColumnType.GetGenericArguments().Length > 0 && DataServiceUtilities.IsEntityType(this.ColumnType.GetGenericArguments()[0], this.Table.DataModel.ContextType)) { TableProvider tp = this.Table.DataModel.Tables .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType)); if (tp != null) { DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(this.Table) { ColumnType = typeof(string), Name = "Null(" + this.Table.Name + "." + this.Name + ")" }; ((DataServiceTableProvider)tp).AddColumn(nullColumn); Association = new DataServiceAssociationProvider( AssociationDirection.ManyToMany, this, nullColumn, new List<string>() { this.Table.Name + "({0})/" + this.Name }); } } }
internal void Initialize() { // If we don't have a PropertyInfo, we're likely dealing with an association column // we created in TryCreateAssociationColumn, and we should skip it here if (EntityTypeProperty == null) { return; } // Check if there is an Entity that has the same type as this column. If so, we treat this column as an entity ref TableProvider parentTable = Table.DataModel.Tables.SingleOrDefault(t => t.EntityType == ColumnType); if (parentTable == null) { return; } DataServiceColumnProvider toColumn = null; ColumnProvider parentPK = null; // Look for the matching Entity Set column in the parent table foreach (DataServiceColumnProvider parentColumn in parentTable.Columns) { // Pick up the parent table's PK column on the way if (parentColumn.IsPrimaryKey) { parentPK = parentColumn; } // The Entity Set column is expected to be of a type like IList<AcmeProduct> if (!parentColumn.ColumnType.IsGenericType) { continue; } Type childrenType = parentColumn.ColumnType.GetGenericArguments()[0]; if (childrenType == Table.EntityType) { toColumn = parentColumn; break; } } var foreignKeyNames = new List <string>(); foreignKeyNames.Add(Name + "." + parentPK.Name); if (toColumn == null) { Association = new DataServiceAssociationProvider(AssociationDirection.ManyToOne, this, parentTable, foreignKeyNames); } else { Association = new DataServiceAssociationProvider(AssociationDirection.ManyToOne, this, toColumn, foreignKeyNames); // Create the reverse association var reverseAssociation = new DataServiceAssociationProvider(AssociationDirection.OneToMany, toColumn, this, foreignKeyNames); toColumn.Association = reverseAssociation; } }
internal void Initialize() { // If we don't have a PropertyInfo, we're likely dealing with an association column // we created in TryCreateAssociationColumn, and we should skip it here if (EntityTypeProperty == null) return; // Check if there is an Entity that has the same type as this column. If so, we treat this column as an entity ref TableProvider parentTable = Table.DataModel.Tables.SingleOrDefault(t => t.EntityType == ColumnType); if (parentTable == null) return; DataServiceColumnProvider toColumn = null; ColumnProvider parentPK = null; // Look for the matching Entity Set column in the parent table foreach (DataServiceColumnProvider parentColumn in parentTable.Columns) { // Pick up the parent table's PK column on the way if (parentColumn.IsPrimaryKey) parentPK = parentColumn; // The Entity Set column is expected to be of a type like IList<AcmeProduct> if (!parentColumn.ColumnType.IsGenericType) continue; Type childrenType = parentColumn.ColumnType.GetGenericArguments()[0]; if (childrenType == Table.EntityType) { toColumn = parentColumn; break; } } var foreignKeyNames = new List<string>(); foreignKeyNames.Add(Name + "." + parentPK.Name); if (toColumn == null) { Association = new DataServiceAssociationProvider(AssociationDirection.ManyToOne, this, parentTable, foreignKeyNames); } else { Association = new DataServiceAssociationProvider(AssociationDirection.ManyToOne, this, toColumn, foreignKeyNames); // Create the reverse association var reverseAssociation = new DataServiceAssociationProvider(AssociationDirection.OneToMany, toColumn, this, foreignKeyNames); toColumn.Association = reverseAssociation; } }