This problem seems a little more interesting that the usual mapping problems.
I have a method that will execute a delete with NHibernate but I am hung on some apparently simple issue. I have looked over various other similar issues that might relate to this but after a couple of hours I am hung up on it.
I have this method:
public void DeleteOrganization(Guid actorId)
{
using (var session = _nhibernate.OpenSession())
{
ITransaction transaction = session.BeginTransaction();
try
{
session.Delete(actorId);
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
throw;
}
}
}
And this HBM map:
<class name="Actor, Domain.Entities" table="Actor" lazy="false">
<id name="ActorId" column="ActorId" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
I still seem to get stuck here. The kicker is that it is hung on the Guid. Any ideas?
The trouble here was that I was mapping an Organization object and trying to delete the id(not the record itself). In my previous code, I should have been trying to delete the Organization object. The correct code is as follows:
public void DeleteOrganization(Guid actorId)
{
using (var session = _nhibernate.OpenSession())
{
ITransaction transaction = session.BeginTransaction();
try
{
var Organization = (from p in session.Query<Organization>()
where p.ActorId == actorId
orderby p
select p).First();
session.Delete(Organization);
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
throw;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.