How are relationships organized in devExpress XAF

2.2k views Asked by At

I just can't understand all this [Association] stuff even after reading online documentation. I have this database enter image description here

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

2

There are 2 answers

0
Uranus On BEST ANSWER

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:

  • If you are mapping to an existing database, you cannot declare the relationship this way, because the Услуги table does not have a separate column to reference the Очередь table. So, if you cannot change the database, you can declare only the one-to-many relationship;
  • If you are generating the database based on the model, you can declare the relationship as your needs dictate. However, I am not sure that you are actually want one-to-one relationship. I will elaborate on this further.

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.

0
Serdin Çelik On
  public class Departman : XPObject
{
    public Departman(Session session)
        : base(session)
    {
    }
    public override void AfterConstruction()
    {
        base.AfterConstruction();

    }

    [Association]
    public Fabrika Fabrika;

}

public class Fabrika : XPObject { public Fabrika(Session session) : base(session) { } public override void AfterConstruction() { base.AfterConstruction();

    }
    [Association]
    public Departman Departman;

}

This exammple of one to one relations in XAF. More Examples :https://documentation.devexpress.com/eXpressAppFramework/113640/Getting-Started/Comprehensive-Tutorial/Business-Model-Design/Business-Model-Design-with-XPO/Business-Model-Design-with-eXpress-Persistent-Objects