Relationship class

Namespace: ReFlex.Data namespace
Assembly: ReFlex.Data.dll

Syntax

public class Relationship

Constructors

public Relationship(Type entityType, Type subjectEntityType, RelationshipTypeEnum relationshipType)
public Relationship(Type entityType, Type subjectEntityType, string explicitMappingName, RelationshipTypeEnum relationshipType)

Remarks

Passed to ObjectFactory methods to define the relationships that should be taken into account when retrieving result sets of objects.

The EntityType is the external type being related to either the subject (the type of objects that will be returned in the result set), or an EntityType of another Relationship object to be included in the request.

The RelationshipType defines how the relationship join is made. A strong parent means the EntityType is a parent of the SubjectEntityType, and an inner join should be used, where a weak parent would use a left join. A strong child means the EntityType is a child of the SubjectEntity type, and an inner join should be used, where a weak child would use a left join.

The ExplicitMappingName is used where an object may have multiple relationships of the same type to another object. These explicit mappings are defined at that objects class definition using the RelationalExplicitMapping attribute.

Examples

// this example retrieves a list of Contact objects that relate to a Company that is in a specific IndustryID

// the Company type as a strong parent of Contact i.e. Contact.CompanyID must match a Company.CompanyID
Relationship pageRelationship = new Relationship(typeof(Company), typeof(Contact), RelationshipTypeEnum.StrongParent);
// Company also has a relationship to Industry i.e. Company.IndustryID must match an Industry.IndustryID
Relationship pageRelationship = new Relationship(typeof(Industry), typeof(Company), RelationshipTypeEnum.StrongParent);

// now the criterion object can reference the Company or Industry in addition to Contact
Criterion<Industry> industryCriterion = new Criterion<Industry>(CriteriaOperatorEnum.And)
    .Add("IndustryName", "Accomodation", ComparisonOperatorEnum.Like, CriteriaOperatorEnum.And));

// get matching Contacts list
List<Contact> contact;
using (ObjectFactory<Contact> mapper = new ObjectFactory<Contact>())
    contact = mapper.GetDataObjects(industryCriterion, new Ordering().Add<Contact>("FirstName", Direction.Ascending));