At least in NH3.3.x, it looks as though the 'check' attribute for the
HBM 'sql-delete' element isn't exposed by the Conformist mappings. I've
got an extremely nasty piece of code which I think should work for NH3,
but because it relies upon the internal implementation details of NH it
could break at any point in the future...:
// Very nasty kludge that relies on private implementation details and
could break horribly at any point
try
{
CustomizersHolder.AddCustomizer(typeof(Review), (IClassMapper m)
=>
{
FieldInfo sqlDeleteField =
typeof(ClassMapper).GetField("classMapping");
ClassMapper mapperImpl = (ClassMapper)m;
HbmClass classMapping =
(HbmClass)sqlDeleteField.GetValue(mapperImpl);
classMapping.SqlDelete.check = HbmCustomSQLCheck.None;
classMapping.SqlDelete.checkSpecified = true;
});
}
catch (Exception ex)
{
throw new Exception("Unable to manipulate private contents of
NHibernate class mapper - has the NHibernate version been updated?",
ex);
}
It's also possible to add arbitrary XML to the
NHibernate.Cfg.Configuration instance after you've added the ByCode
mappings, so a cleaner approach (but more work) would be consist of
creating some interface that's shared between the mapping assembly and
the NH configuration which acts as a holder for a raw HBM payload - e.g.
var config = new NHibernate.Cfg.Configuration();
config.AddDeserializedMapping(byCodeMappings, null);
IEnumerable<Type> customXmlMappings =
FindTypesImplementingCustomXmlMappingInterface();
foreach (var t in customXmlMappings)
{
config.AddXmlString(((CustomXmlMappingInterface)Activator.CreateInstance
(t)).GetHbmString());
}
/Pete
From: [email protected] [mailto:[email protected]] On
Behalf Of Moiz kachwala
Sent: 15 May 2013 06:59
To: [email protected]
Subject: [nhusers] Nhibernate SqlDelete(stored procedure) generates
error. Set Expectation on SqlDelete
I am creating an application using Nhibernate . I am executing the
Stored procedure from my mapping class.
But it is giving me the error
Batch update returned unexpected row count from update; actual row
count: -1; expected: 1
Here is the mapping file. I am trying to delete the Reviews and Even I
want to delete the objectives if any.
public ReviewMap()
{
Table("Reviews");
SqlDelete("exec DeleteReview ?");
List(x => x.Objectives, m =>
{
m.Table("Objectives");
m.Cascade(Cascade.All.Include(Cascade.DeleteOrphans));
m.Key(k => k.Column("ReviewId"));
m.Where("DeletionDate is null");
m.OrderBy("OrderNo");
m.Index(x => x.Column("OrderNo"));
m.Inverse(true);
}, m => m.OneToMany());
}
public ObjectiveMap()
{
Table("Objectives");
// Use "soft deletes" to allow us to capture results against
deleted items
Where("DeletionDate is null");
SqlDelete("update Objectives set DeletionDate =
getutcdate(), OrderNo = 1 where id=?");
ManyToOne(x => x.Review, m =>
{
m.Column("ReviewId");
m.NotNullable(true);
});
Property(x => x.Details, m =>
{
m.NotNullable(true);
m.Length(1000);
m.Column("Details");
});
Property("OrderNo", m =>
{
m.NotNullable(false);
});
}
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.