Ich weiß, wie man bidirektionale Beziehungen mit NHibernate abbildet, aber jemand weiß eine effektive Technik, um sie "entwicklungssicher" zu machen.Entwickler-sichere bidirektionale Beziehungen mit NHibernate
Was ich damit meine, ist, dass, sobald ein Ende der Beziehung hergestellt wird, sollte das andere Ende auch eingestellt werden, zum Beispiel:
[Test]
public void TestBidirectionalRelationships_WhenAddingOptionToProduct()
{
var product = new Product();
var productOption = new ProductOption();
product.AddOption(productOption);
Assert.That(product.Options.Contains(productOption));
Assert.That(productOption.Product, Is.EqualTo(product);
}
[Test]
public void TestBidirectionalRelationships_WhenSettingProductOnOption()
{
/* Alternatively, productOption.Product would have no public setter */
var product = new Product();
var productOption = new ProductOption();
productOption.Product = product;
Assert.That(product.Options.Contains(productOption));
Assert.That(productOption.Product, Is.EqualTo(product);
}
Wie würde man dies erreichen, ohne die Herstellung von Code horrend komplex, und während NHibernate auch glücklich zu halten?
Das hängt davon ab, was du meinst mit „horrend Komplex“ – Paco