I'm using NHibernate for data access and have a situation like this
public class B
{
public virtual long Id { get; set;}
// ...
}
public class B
{
public virtual long Id { get; set;}
public virtual A AReference { get; set; }
// ...
}
and mapping
public class BMapping : ClassMapping<B>
{
// ...
ManyToOne(x => x.AReference, mapper =>
{
mapper.ForeignKey("none");
mapper.Insert(false);
mapper.Update(false);
mapper.Column("a_id");
mapper.Fetch(FetchKind.Join);
mapper.NotFound(NotFoundMode.Ignore);
});
// ...
}
My problem is that there is no foreign key constraint between tableA
and tableB
, so there are cases where tableB
references nonexistent items. (I know that's bad, but I can't do anything about it.)
Setting
mapper.NotFound(NotFoundMode.Ignore);
allows me to retrieve data without "No row with the given identifier exists" exceptions, but it seems NHibernate is trying to load those orphaned items using separate selects like
SELECT ... FROM tableA WHERE tableA.ID = ?
Can I disable that additional queries and how?
As discussed here NHibernate Prevent Lazy Loading of unmatched reference and here Lazy loading for NHibernate with Ignore.NotFound the point is:
Check this for
and mostly the link provided there
How to use 0 instead of null for foreign keys
to get some understanding how to create custom PocoEntityTuplizer to be used that.