Association in Entity Framework
Association defines a relationship between two entities in an Entity Framework. The association is defined in a conceptual model by the "Association" Element and each relationship contains two ends that describe the entity type and multiplicity type (one to one, zero-or -one, one to many, many to many). The relationship may be managed by the "Referential" constraint. Referential Constraints contain information about a principal role and a dependent role in a relationship.
Entity Framework supports two types of association
- Foreign key columns Association
- Independent association.
Foreign key association
You may create or change a relationship by modifying the foreign key value of the dependent object when the foreign key properties are included in EDM. This type of association is called a foreign key association. In this type of association, a foreign key must be exposed.
Example

In this current example, a foreign key is defined between Customer and People (Person in EDM) in the storage model, which means the foreign key is defined in the database.
The following are the storage model and conceptual model. In both storage and conceptual models, the foreign key is defined. In the following sample association set, the association and navigation properties are automatically bound or created.
<edmx:StorageModels>
<Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="AdventureWorksModelStoreContainer">
..........
..........
<AssociationSet Name="FK_Customer_Person" Association="AdventureWorksModel.Store.FK_Customer_Person">
<End Role="Person" EntitySet="Person" />
<End Role="Customer" EntitySet="Customer" />
</AssociationSet>
</EntityContainer>
...........
...........
<Association Name="FK_Customer_Person">
<End Role="Person" Type="AdventureWorksModel.Store.Person" Multiplicity="1" />
<End Role="Customer" Type="AdventureWorksModel.Store.Customer" Multiplicity="0..1" />
<ReferentialConstraint>
<Principal Role="Person">
<PropertyRef Name="PersonId" />
</Principal>
<Dependent Role="Customer">
<PropertyRef Name="CustomerID" />
</Dependent>
</ReferentialConstraint>
</Association>
.......
.......
</Schema>
</edmx:StorageModels>
<edmx:ConceptualModels>
<Schema Namespace="AdventureWorksModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="AdventureWorksEntities" annotation:LazyLoadingEnabled="true">
.........
.........
<AssociationSet Name="FK_Customer_Person" Association="AdventureWorksModel.FK_Customer_Person">
<End Role="Person" EntitySet="People" />
<End Role="Customer" EntitySet="Customers" />
</AssociationSet>
.......
.......
<Association Name="FK_Customer_Person">
<End Type="AdventureWorksModel.Person" Role="Person" Multiplicity="1" />
<End Type="AdventureWorksModel.Customer" Role="Customer" Multiplicity="0..1" />
<ReferentialConstraint>
<Principal Role="Person">
<PropertyRef Name="PersonId" />
</Principal>
<Dependent Role="Customer">
<PropertyRef Name="CustomerID" />
</Dependent>
</ReferentialConstraint>
</Association>
.......
.......
</Schema>
</edmx:ConceptualModels>




Jessica StephenPosted Feb 16, 2012, 11:03 PM
Thank you very much for the article.
Monika AroraPosted Feb 16, 2012, 11:01 PM
Its a very nice and useful article.
Laura ParkerPosted Feb 16, 2012, 10:59 PM
Comprehensively explained
Amit MaheshwariPosted Feb 16, 2012, 10:52 PM
Hi, Jignesh it's well explanation about entity framework, So keep going and thanks for sharing.......
Nitin SinghPosted Feb 16, 2012, 10:47 PM
This article is so valuable, keep it up and thanks for sharing.