Export (0) Print
Expand All

AssociationAttribute Class

Designates a property to represent a database association, such as a foreign key relationship.

Namespace:  System.Data.Linq.Mapping
Assembly:  System.Data.Linq (in System.Data.Linq.dll)

[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false)]
public sealed class AssociationAttribute : DataAttribute

Use this attribute to represent an association in a database, such as the relationship between a foreign key and a primary key.

In the following example, the Order class includes an AssociationAttribute attribute to associate Orders with Customers.

    private EntityRef<Customer> _Customer;
	// ...
	[Association(Name="FK_Orders_Customers", Storage="_Customer", ThisKey="CustomerID", IsForeignKey=true)]
	public Customer Customer
	{
		get
		{
			return this._Customer.Entity;
		}
		set
		{
			Customer previousValue = this._Customer.Entity;
			if (((previousValue != value) 
						|| (this._Customer.HasLoadedOrAssignedValue == false)))
			{
				this.SendPropertyChanging();
				if ((previousValue != null))
				{
					this._Customer.Entity = null;
					previousValue.Orders.Remove(this);
				}
				this._Customer.Entity = value;
				if ((value != null))
				{
					value.Orders.Add(this);
					this._CustomerID = value.CustomerID;
				}
				else
				{
					this._CustomerID = default(string);
				}
				this.SendPropertyChanged("Customer");
			}
		}
	}

System.Object
  System.Attribute
    System.Data.Linq.Mapping.DataAttribute
      System.Data.Linq.Mapping.AssociationAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

Community Additions

ADD
Show:
© 2014 Microsoft