I wrote up a very simple test and everything worked fine. Only the Individual table was updated.
Here is the test code
Code:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
namespace BugFix
{
public class Program : IDisposable
{
readonly ISessionFactory sessionFactory;
static void Main(string[] args)
{
try
{
using (Program p = new Program())
{
p.Run();
}
}
catch (Exception e)
{
Console.Error.WriteLine(e.ToString());
}
finally
{
Console.Write("Press ENTER to exit...");
Console.ReadLine();
}
}
public Program()
{
Configuration cfg = new Configuration();
cfg.AddAssembly(System.Reflection.Assembly.GetExecutingAssembly());
this.sessionFactory = cfg.BuildSessionFactory();
}
private void Run()
{
Guid individualUid = Guid.NewGuid();
Guid addressUid = Guid.NewGuid();
const string hongkong = "Hong Kong";
// create test data
using (ISession session = sessionFactory.OpenSession())
{
Address a = new Address();
a.AddressUid = addressUid;
a.Line1 = hongkong;
Individual i = new Individual();
i.IndividualUid = individualUid;
i.First = "Ken";
i.Address1 = a;
session.Save(a);
session.Save(i);
session.Flush();
}
// modify Individual and check profiler Address table should not be updated
using (ISession session = sessionFactory.OpenSession())
{
Individual i = session.Get<Individual>(individualUid);
i.Last = "Tong";
System.Diagnostics.Debug.Assert(i.Address1.Line1 == hongkong, "Address1.Line1 is incorrect");
session.Update(i);
session.Flush();
}
}
#region IDisposable Members
public void Dispose()
{
try
{
if (sessionFactory != null)
{
sessionFactory.Dispose(); // drop tables
}
}
finally
{
}
}
#endregion
}
}
The profiler result is
Code:
exec sp_executesql N'INSERT INTO dbo.Address (Line1, Line2, AddressUid) VALUES (@p0, @p1, @p2)',N'@p0 nvarchar(9),@p1 nvarchar(4000),@p2 uniqueidentifier',@p0=N'Hong Kong',@p1=NULL,@p2='BBEDA802-8FBD-4E84-B821-C3CE55EEECFE'
go
exec sp_executesql N'INSERT INTO dbo.Individual (First, Last, Address1Uid, Address2Uid, IndividualUid) VALUES (@p0, @p1, @p2, @p3, @p4)',N'@p0 nvarchar(3),@p1 nvarchar(4000),@p2 uniqueidentifier,@p3 uniqueidentifier,@p4 uniqueidentifier',@p0=N'Ken',@p1=NULL,@p2='BBEDA802-8FBD-4E84-B821-C3CE55EEECFE',@p3=NULL,@p4='7C740414-CC77-488A-ABFF-B3D738B874EF'
go
exec sp_executesql N'SELECT individual0_.IndividualUid as Individu1_0_2_, individual0_.First as First0_2_, individual0_.Last as Last0_2_, individual0_.Address1Uid as Address4_0_2_, individual0_.Address2Uid as Address5_0_2_, address1_.AddressUid as AddressUid1_0_, address1_.Line1 as Line2_1_0_, address1_.Line2 as Line3_1_0_, address2_.AddressUid as AddressUid1_1_, address2_.Line1 as Line2_1_1_, address2_.Line2 as Line3_1_1_ FROM dbo.Individual individual0_ left outer join dbo.Address address1_ on individual0_.Address1Uid=address1_.AddressUid left outer join dbo.Address address2_ on individual0_.Address2Uid=address2_.AddressUid WHERE individual0_.IndividualUid=@p0',N'@p0 uniqueidentifier',@p0='7C740414-CC77-488A-ABFF-B3D738B874EF'
go
exec sp_executesql N'UPDATE dbo.Individual SET Last = @p0 WHERE IndividualUid = @p1',N'@p0 nvarchar(4),@p1 uniqueidentifier',@p0=N'Tong',@p1='7C740414-CC77-488A-ABFF-B3D738B874EF'
go
You can download the test application here
http://www.box.net/shared/z2gfzexx1j