0
I have a model for Municipio. This model can be referenced by several other models (Customer, Supplier, Carrier, Seller...). Each of these models has an association N:1 for Municipio, +/- so:
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 Municipality model, +/- so:
public class Municipio: XPLiteObject {
...
[Association]
public XPCollection<Cliente> Clientes {
get { return GetCollection<Order>("Clientes"); }
}
}
I do not want (I would not like) to declare this association in the Municipio model, because I will not reference the list of customers from Municipio. And also because I would have several models referencing Municipio, and I don’t need to get the list of any of them from Municipio. Another aggravating factor is that the Municipio model is already tested, and when I add another model referencing Municipio, e.g. 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 mandatory for each associated model (Customer, Seller...), or whether I can keep the reference only in the model that maintains the relationship. And, if it is mandatory, whether I should name each of the associations to disambiguate the references, thus:
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); }
}
If it’s MANDATORY, let’s do it, right? I find it hard, but I can live with it :)
– Milton Terre
You can always create code templates to facilitate this, it will depend on the IDE and plugins used, in my case I use the
CodeRush
and it already comes with some templates that I customized to get more of my taste, if use theCodeRush
test the templatesxpa
andxpcl
– Leandro Godoy Rosa