Back to Devexpress

NoForeignKeyAttribute Class

xpo-devexpress-dot-xpo-f56c2909.md

latest2.8 KB
Original Source

NoForeignKeyAttribute Class

Disables automatic creation of the FOREIGN KEY constraints.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class NoForeignKeyAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=True)>
Public NotInheritable Class NoForeignKeyAttribute
    Inherits Attribute

Remarks

The following code demonstrates how to use the NoForeignKeyAttribute :

csharp
public class Person : XPObject
{
    // ...
    [Association("Person-Orders")]
    public XPCollection<Order> Orders {
        get { return GetCollection<Order>(nameof(Orders)); }
    }
}

public class Order : XPObject {
    // ...
    [Association("Person-Orders"), NoForeignKey]
    public Person PersonID {
        get { return fPersonID; }
        set { SetPropertyValue(nameof(PersonID), ref fPersonID, value); }
    }
    Person fPersonID;

}
vb
Class Person
   Inherits XPObject
   ' ...
   <Association("Person-Orders")> _
   Public ReadOnly Property Orders() As XPCollection(Of Order)
      Get
         Return GetCollection(Of Order)(NameOf(Orders))
      End Get
   End Property
End Class

Class Order
   Inherits XPObject
   ' ...
   <Association("Person-Orders"), NoForeignKey()> 
   Public Property Person() As PersonID
       Get
           Return fPerson
       End Get
       Set(ByVal value as PersonID)
           SetPropertyValue(NameOf(Person), fPerson, value)
       End Set
   End Property
   Private fPerson As PersonID

End Class

Note

Foreign keys preserve referential integrity in a relational database. A lack of referential integrity in a database can lead to errors or returning incomplete data without indication of an error. To enforce the data integrity at the database level, do not disable automatic creation of the FOREIGN KEY constraints (or always add them manually).

Inheritance

Object Attribute NoForeignKeyAttribute

See Also

NoForeignKeyAttribute Members

Built-In Attributes

DevExpress.Xpo Namespace