Association on Devexpress XPO models

0

I have a template for Municipality. This model can be referenced by several other models (Customer, Supplier, Carrier, Salesman ...). Each of these models has an association N: 1 for Municipio, +/- thus:

public class Cliente: XPLiteObject {
  ...
  Municipio: fMunicipio;
  [Association]
  public Municipio Municipio {
    get { return fMunicipio; }
    set { SetPropertyValue("Municipio", ref fMunicipio, value); }
}

According to the XPO documentation, I must declare this association at the other end, in the Municipio model, +/- thus:

public class Municipio: XPLiteObject {
  ...
  [Association]
  public XPCollection<Cliente> Clientes { 
    get { return GetCollection<Order>("Clientes"); }
  }     
}

I do not want (do not like) to declare this association in the model Municipio, because I will not refer to the list of clients from Municipality. And also because I would have several models referencing Municipio, and I do not need to get the list of any of them from Municipality. Another problem is that the model Municipio is already tested, and when I add another model referencing Municipio, eg Distributor, I do not want to change the Municipio model, adding another association in it.

My question is whether the association at the other end (Municipio) is obligatory for each associated model (Client, Vendor ...), or if I can keep the reference only in the model that maintains the relation. And, if it is mandatory, I should name each of the associations to disambiguate the references, like this:

public class Municipio: XPLiteObject {
  ...
  [Association("Cliente-Municipio)]
  public XPCollection<Cliente> Clientes { 
    get { return GetCollection<Order>("Clientes"); }
  }     
  [Association("Fornecedor-Municipio)]
  public XPCollection<Fornecedor> Fornecedores { 
    get { return GetCollection<Order>("Formecedores"); }
  }     
}

public class Cliente: XPLiteObject {
  ...
  Municipio: fMunicipio;
  [Association("Cliente-Municipio)]
  public Municipio Municipio {
    get { return fMunicipio; }
    set { SetPropertyValue("Municipio", ref fMunicipio, value); }
}

public class Fornecedor: XPLiteObject {
  ...
  Municipio: fMunicipio;
  [Association("Fornecedor-Municipio)]
  public Municipio Municipio {
    get { return fMunicipio; }
    set { SetPropertyValue("Municipio", ref fMunicipio, value); }
}
    
asked by anonymous 10.07.2014 / 17:54

1 answer

0

It is mandatory to have the association on both sides of the template, Xpo inspects the two tips to know the type of association that was made.

The name of the association is usually optional, associations of type N: 1 it can solve itself by inspecting the class names, in this case it should only have problems in case you have more than one association between the same models.

The name will be mandatory in the case of N: N associations, and in these cases I usually also set the UseAssociationNameAsIntermediateTableName = true property in the association statement to have greater control of table creation.

    
11.07.2014 / 16:04