// Returns the base types, this type and all the derived types of this type. public static IEnumerable <IEntityTypeConfiguration> ThisAndBaseAndDerivedTypes(this ODataModelBuilder modelBuilder, IEntityTypeConfiguration entity) { Contract.Assert(modelBuilder != null); Contract.Assert(entity != null); return(entity.BaseTypes() .Concat(new[] { entity }) .Concat(modelBuilder.DerivedTypes(entity))); }
public void DerivedTypes_Works() { ODataModelBuilder builder = GetMockVehicleModel(); EntityTypeConfiguration vehicle = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "vehicle").Single(); EntityTypeConfiguration car = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "car").Single(); EntityTypeConfiguration motorcycle = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "motorcycle").Single(); EntityTypeConfiguration sportbike = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "sportbike").Single(); Assert.Equal( builder.DerivedTypes(vehicle).Select(e => e.Name).OrderBy(name => name), new[] { sportbike, motorcycle, car }.Select(e => e.Name).OrderBy(name => name)); }
// Returns all the derived types of this type. public static IEnumerable <IEntityTypeConfiguration> DerivedTypes(this ODataModelBuilder modelBuilder, IEntityTypeConfiguration entity) { if (modelBuilder == null) { throw Error.ArgumentNull("modelBuilder"); } if (entity == null) { throw Error.ArgumentNull("entity"); } IEnumerable <IEntityTypeConfiguration> derivedEntities = modelBuilder.StructuralTypes.OfType <IEntityTypeConfiguration>().Where(e => e.BaseType == entity); foreach (IEntityTypeConfiguration derivedEntity in derivedEntities) { yield return(derivedEntity); foreach (IEntityTypeConfiguration derivedDerivedEntity in modelBuilder.DerivedTypes(derivedEntity)) { yield return(derivedDerivedEntity); } } }