epitka
unread,Jul 1, 2009, 1:07:29 PM7/1/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
I have a very unusual problem with one relationship in my class (and
only this one) out of some 60 classes. Problem is that the unit test
that tests mapping passes on my local machine, but fails on the build
server. Mind you everything is pointing to the same database, problem
is not with a data. Problem is that on my machine, when unit test is
run, collection is uninitialized until accessed. On the server, is
shows as initialized. Here is the unit test (please do not comment on
unit test itself, it is what it is):
[Test]
public void Can_Load_With_ClientNotes()
{
Domain.Client.Entities.Client client =
clientRepository.FindByNumber(261).FirstOrDefault();
Assert.That(client, Is.Not.Null);
Assert.That(NHibernateUtil.IsInitialized
(client.LazyNotes),Is.False, "IsInitialized - before");
NHibernateUtil.Initialize(client.LazyNotes);
Assert.That(NHibernateUtil.IsInitialized
(client.LazyNotes), Is.True, "IsInitialized - after");
Assert.That(client.LazyNotes.Any(),Is.True, "LazyNotes");
Assert.That(client.LazyNotes.Count(), Is.GreaterThan(0));
}
Here is the mapping for the Client and ClientNote
ClientMap
public class ClientMap : ClassMap<Client.Entities.Client>
{
public ClientMap()
{
DefaultAccess.AsCamelCaseField(Prefix.Underscore);
WithTable("vw_Client");
Id(x => x.Id, "ClientId");
Map(x => x.Name, "ClientNameTxt");
Map(x => x.Number, "ClientNum");
Map(x => x.EnrollmentSize, "EnrollmentSizeNum");
References(x => x.AccountType, "AcctTypeCd");
References(x => x.LineOfBusiness, "LineOfBusinessCd");
HasMany(x => x.EagerNotes).KeyColumnNames.Add
("ClientId").Not.LazyLoad();
HasMany(x => x.LazyNotes).KeyColumnNames.Add
("ClientId").LazyLoad().AsBag();
HasMany(x => x.AccountTypeHistory)
.KeyColumnNames.Add("ClientId")
.Cascade.SaveUpdate();
ClientNote:
public class ClientNoteMap : ClassMap<ClientNote>
{
public ClientNoteMap()
{
DefaultAccess.AsCamelCaseField(Prefix.Underscore);
WithTable("vw_D_ClientNote");
Id(x => x.Id, "NoteId");
Map(x => x.Subject, "NoteSubjectTxt");
Map(x => x.CreationDate, "NoteCrtDt");
Map(x => x.ShortText, "NoteShrtTxt");
Map(x => x.Text, "NoteTxt");
}
}
Facts:
1. this Assert.That(NHibernateUtil.IsInitialized
(client.LazyNotes),Is.False, "IsInitialized - before"); passes on my
machine, and same code fails on build server.
2. I take this dll and put it in the web bin directory, and I step
through the code and this is what I see for generated proxy. All other
collections are as PersistentGenericBag, except for LazyNotes? How
come?
?CurrentBid.Client
{ClientProxybef6f8a3309c43f7b7b98a0d8f36d526}
[ClientProxybef6f8a3309c43f7b7b98a0d8f36d526]:
{ClientProxybef6f8a3309c43f7b7b98a0d8f36d526}
base {SR.Domain.Common.Infrastructure.PersistentObject}:
{ClientProxybef6f8a3309c43f7b7b98a0d8f36d526}
AccountType: {AccountTypeProxyf2cfb29f153b4e8abd4cfcc946b97213}
AccountTypeHistory:
{NHibernate.Collection.Generic.PersistentGenericBag<SR.Domain.Client.Entities.ClientAccountTypeHistoryItem>}
ClientType: null
EagerNotes: Count = 0
EnrollmentSize: 35161
LazyNotes: Count = 0
LineOfBusiness:
{LineOfBusinessProxy7010d97df001455f8e464a03477c23d3}
Name: "Purdue University"
Number: 261