I just can't understand all this [Association] stuff even after reading online documentation. I have this database
How can I make one-to-one relationship in devExpress XAF (c#)? For example, Очередь-ServId to Услуги - Id? What shall I add?
This is my code
Сlass Queue is "Очередь"
[DefaultClassOptions, ObjectCaptionFormat("{0:ClientNumber}"), DefaultProperty("ClientNumber"), XafDisplayName("Моя очередь"), ImageName("BO_List")]
public class Queue : BaseObject
{
public Queue(Session session) : base(session) { }
private String _ClientStatus;
[Size(50)]
[XafDisplayNameAttribute("Статус")]
public String ClientStatus
{
get { return _ClientStatus; }
set { SetPropertyValue("ClientStatus", ref _ClientStatus, value); }
}
private int _ServId;
[XafDisplayNameAttribute("Id")]
public int ServId
{
get { return _ServIdr; }
set { SetPropertyValue("ServId", ref _ServId, value); }
}
private int _ClientNumber;
[XafDisplayNameAttribute("Номер в очереди")]
public int ClientNumber
{
get { return _ClientNumber; }
set { SetPropertyValue("ClientNumber", ref _ClientNumber, value); }
}
private DateTime _GetDate;
[XafDisplayNameAttribute("Дата")]
public DateTime GetDate
{
get { return _GetDate; }
set { SetPropertyValue("GetDate", ref _GetDate, value);}
}
}
Services is "Услуги"
//Услуги
public class Services : BaseObject
{
public Services(Session session) : base(session) { }
private String _Name;
[Size(SizeAttribute.Unlimited)]
public String Name
{
get { return _Name; }
set { SetPropertyValue("Name", ref _Name, value); }
}
}
Thank you
The way you define the relationship between objects depends on you business logic requirements. The One-to-One relationship is described here in the documentation: How to: Implement One-to-One Relationships. However, there are two points you need to take into account:
To decide which type of association you need, you have to answer to a question "how will you display data to end users?".
If you want to display the service name when displaying a queue detail data, change the Queue.ServId property type to Services. This is sufficient.
If it is not a one-to-one relation and there will be multiple queue items associated with a single service, you might want to display a collection of queue items when displaying the service detail data. For this purpose, you need to declare the full association. Besides changing the foreign key property type in the Queue class, you also need to declare a collection property in the Service class. This technique is described in this article: Introduction to One-to-Many Relationships.
And only in the case when you need to logically restrict users from associating multiple Queue items with a single Service item you will declare the one-to-one association. In this situation, you will need to update your database schema, because the Услуги table needs a separate column to store the reference to the Очередь table.