Hi,
I have some difficulties altering mapping for child object.
Here's the model:
public class Product {
public virtual int Id { get; protected set; }
public virtual BinaryContent Image { get; set; }
}
public class BinaryContent {
public virtual int Id { get; protected set; }
public virtual byte[] Content { get; set; }
public virtual string ContentType { get; set; }
}
The rules are:
1. Product can have only one Image (BinaryContent)
2. BinaryContent should always be related to a product.
Rule 2 implies if the Product gets deleted then the Image should be gone as
well.
So here's the test for it:
[Test]
public void DeleteProductDeletesImage() {
var p = new Product();
p.AssignImage(new BinaryContent {
ContentType = "no/content",
Content = Encoding.ASCII.GetBytes("nothing")
});
int prodId;
int imgId;
using (var sess = OpenSession()) {
sess.Save(p);
sess.Flush();
prodId = p.Id;
imgId = p.Image.Id;
sess.Delete(p);
sess.Flush();
}
using (var sess = OpenSession()) {
var p2 = sess.Get<Product>(prodId);
Assert.IsNull(p2);
var img2 = sess.Get<BinaryContent>(imgId);
Assert.IsNull(img2); // CANNOT MAKE
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---