Ok, i will try this snippet and be back later Thanks Peter
On 25 Apr., 09:55, Maximilian Raditya <[email protected]> wrote: > Hmm... I'm not sure I understand correctly what you're doing there, but > basically you need to do it in the follower order: > - create a new Employee > - create a new Address > - create a new EmployeeAddress and reference both the Employee and Address > - add the EmployeeAddress to Employee.Addresses collection > - save the Address first > - and then save the Employee > > Here's how it would be implemented: > > using (var session = sessionFactory.OpenSession()) > { > using (var tx = session.BeginTransaction()) > { > var employee = new Employee > { > FullName = "Alice" > }; > var address = new Address > { > AddressLine = "1st Wonderland > St." > }; > var employeeOfficeAddress = new EmployeeAddress > { > Employee = > employee, > Address = > address, > AddressType = > AddressType.Office > }; > employee.Addresses.Add(employeeOfficeAddress); > > session.SaveOrUpdate(address); > session.SaveOrUpdate(employee); > > tx.Commit(); > } > } > > On Thu, Apr 25, 2013 at 1:33 PM, Peter Forstmeier < > > > > > > [email protected]> wrote: > > Hi, > > i did the test as follows: > > [Test] > > public void EmployeeMapping() > > { > > var factory = > > MySQLiteSessionFactory.CreateSessionFactory(); > > var employee = new > > ProjectTracker.Domain.Employees.Employee() { > > CreatedBy ="me", > > CreatedAt = DateTime.Today, > > EmployeeId = "10" > > }; > > > var address1 = new EmployeeAddress(); > > address1.CreatedBy ="me"; > > address1.CreatedAt = DateTime.Today; > > address1.Address = new Address() { > > ZipCode = "88161" > > }; > > address1.Employee = employee; > > > var addressList = new > > System.Collections.Generic.List<EmployeeAddress>(); > > > addressList.Add(address1); > > // employee.Addresses = addressList; > > new > > > PersistenceSpecification<ProjectTracker.Domain.Employees.Employee>(factory.OpenSession()) > > > /* > > .CheckProperty(c => c.CreatedAt, > > DateTime.Today) > > .CheckProperty(c => c.UpdatedAt, > > DateTime.Today) > > .CheckProperty(c => c.CreatedBy, > > WindowsIdentity.GetCurrent().Name) > > .CheckProperty(c => c.EmployeeId, "10") > > .CheckProperty(c => c.HoursPerWeek, > > Convert.ToDouble(40.5)) > > .CheckProperty(c => c.HireDate, > > DateTime.Today) > > */ > > .CheckProperty(c => c.CreatedAt, > > employee.CreatedAt) > > .CheckProperty(c => c.UpdatedAt, > > DateTime.Today) > > .CheckProperty(c => c.CreatedBy, > > employee.CreatedBy) > > .CheckProperty(c => c.EmployeeId, > > employee.EmployeeId) > > .CheckProperty(c => c.HoursPerWeek, > > Convert.ToDouble(40.5)) > > .CheckProperty(c => c.HireDate, > > DateTime.Today) > > .CheckList(c => > > c.Addresses,employee.Addresses) > > .VerifyTheMappings(); > > } > > NHibernate: INSERT INTO Employees (Version, CreatedAt, CreatedBy, > > UpdatedAt, UpdatedBy, EmployeeId, Firstname, Lastname, HoursPerWeek, > > BirthDate, HireDate, SickDays, VacationDays, Salutation_id, Id) VALUES > > (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, > > @p13, @p14);@p0 = 1 [Type: Int32 (0)], @p1 = 25.04.2013 08:31:00 > > [Type: DateTime (0)], @p2 = 'FORSTMEIER\Peter Forstmeier' [Type: > > String (0)], @p3 = NULL [Type: DateTime (0)], @p4 = NULL [Type: String > > (0)], @p5 = '10' [Type: String (0)], @p6 = NULL [Type: String (0)], > > @p7 = NULL [Type: String (0)], @p8 = 0 [Type: Double (0)], @p9 = NULL > > [Type: DateTime (0)], @p10 = NULL [Type: DateTime (0)], @p11 = 0 > > [Type: Int32 (0)], @p12 = 0 [Type: Int32 (0)], @p13 = NULL [Type: > > Int32 (0)], @p14 = e05d2d11-d224-4f40-8885-a1ab008c5aae [Type: Guid > > (0)] > > > NHibernate: INSERT INTO InheritedAddresses (ZipCode, Town, > > AddressLine1, Country, Id) VALUES (@p0, @p1, @p2, @p3, @p4);@p0 = > > '88161' [Type: String (0)], @p1 = NULL [Type: String (0)], @p2 = NULL > > [Type: String (0)], @p3 = NULL [Type: String (0)], @p4 = > > 392b2313-115b-49d0-aeb1-a1ab008c5ab2 [Type: Guid (0)] > > > NHibernate: INSERT INTO EmployeeAddresses (Version, CreatedAt, > > CreatedBy, UpdatedAt, UpdatedBy, AddressType, EmployeeId, AddressId, > > Id) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8);@p0 = 1 > > [Type: Int32 (0)], @p1 = 25.04.2013 00:00:00 [Type: DateTime (0)], @p2 > > = 'me' [Type: String (0)], @p3 = 25.04.2013 08:31:00 [Type: DateTime > > (0)], @p4 = 'FORSTMEIER\Peter Forstmeier' [Type: String (0)], @p5 = > > 'Home' [Type: String (0)], @p6 = e05d2d11-d224-4f40-8885-a1ab008c5aae > > [Type: Guid (0)], @p7 = 392b2313-115b-49d0-aeb1-a1ab008c5ab2 [Type: > > Guid (0)], @p8 = 0832ed14-5d69-4521-8e8d-a1ab008c5aa9 [Type: Guid (0)] > > > ) Test Error : > > ProjectTracker.Test.Mappings.EmployeeMappingsFixture.EmployeeMapping > > NHibernate.Exceptions.GenericADOException : could not insert: > > [ProjectTracker.Domain.Employees.EmployeeAddress#0832ed14-5d69-4521-8e8d- > > a1ab008c5aa9][SQL: INSERT INTO EmployeeAddresses (Version, CreatedAt, > > CreatedBy, UpdatedAt, UpdatedBy, AddressType, EmployeeId, AddressId, > > Id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] > > ----> System.Data.SQLite.SQLiteException : SQLite error > > no such table: EmployeeAddresses > > > I try the commented part as well > > Peter > > > -- > > 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 athttp://groups.google.com/group/nhusers?hl=en-US. > > For more options, visithttps://groups.google.com/groups/opt_out. > > -- > Regards, > > Maximilian Haru Raditya -- 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.
