I've got the following two C# classes:
public class Pet
{
public virtual string Id { get; set; }
public virtual string Name { get; set; }
}
public class PetOwner
{
public virtual string Id { get; set; }
public virtual Pet Pet { get; set; }
}
And I'm mapping them by code.
In my PetOwner class I have the following ManyToOne mapping for Pet:
ManyToOne<Pet>("Pet", map =>
{
map.Lazy(LazyRelation.Proxy);
map.Column("Pet_Id");
map.Cascade(Cascade.Persist | Cascade.DeleteOrphans);
map.Insert(true);
map.Update(true);
});
Now when I call delete on my PetOwner class as follows, it works and the Pet is also deleted:
var owner = session.QueryOver<PetOwner>().Take(1).List().FirstOrDefault();
session.Delete(owner);
But the following code does not delete the pet at all (and does not give errors either).
session.Query<PetOwner>().Delete();
Now this is just in my unit tests, and in real life there will be a where clause and I probably won't delete all items, but why is this delete different from the explicit delete using the actual database entity?
Is there a way to get this to work as I'm expecting?