Tried it adding them separately, but same issue.
rental.RentalItems.Add(new RentalItem {Movie = firstMovie, Quantity = 1});
rental.RentalItems.Add(new RentalItem {Movie = secondMovie, Quantity = 2});
repository.Save(rental);
NHibernate: SELECT this_.Id as Id0_0_, this_.City as City0_0_,
this_.LastName as LastName0_0_, this_.FirstName as FirstName0_0_,
this_.PostalCode as Po
NHibernate: SELECT this_.Id as Id1_0_, this_.LastName as LastName1_0_,
this_.FirstName as FirstName1_0_ FROM [Employee]
this_
NHibernate: SELECT this_.Id as Id2_0_, this_.RentalPrice as RentalPr2_2_0_,
this_.Genre as Genre2_0_, this_.Rating as Rating2_0_, this_.ProductionStudi
NHibernate: SELECT this_.Id as Id2_0_, this_.RentalPrice as RentalPr2_2_0_,
this_.Genre as Genre2_0_, this_.Rating as Rating2_0_, this_.ProductionStudi
NHibernate: INSERT INTO [Rental] (OrderDate, Employee_id, Customer_id, Id)
VALUES (@p0, @p1, @p2, @p3); @p0 = '12-5-2009 0:05:57', @p1 = '2fb94e57-5a38
NHibernate: UPDATE [RentalItem] SET Rental_id = @p0, ListIndex = @p1 WHERE
Id = @p2; @p0 = 'bf831e09-5d89-45b3-b878-9c070001a2af', @p1 = '0', @p2 = '0'
TestCase
'Avanade.TDD.Videoheaven.Tests.CreatingTestEntities.can_create_a_rental'
failed: NHibernate.StaleStateException : Unexpected row count: 0; expected:
1
at
NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32
rowCount, IDbCommand statement)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation
expectation)
at
NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection
collection, Object id, ISessionImplementor session)
at
NHibernate.Action.CollectionRecreateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable
executable)
Any thoughts?
On Tue, May 12, 2009 at 12:03 AM, James Gregory <[email protected]>wrote:
> I believe this is the same as another question from a couple of days ago.
> You shouldn't be setting the RentalItems property to a new array, you should
> add items to it.
>
>
> On Mon, May 11, 2009 at 10:43 PM, Tomk <[email protected]> wrote:
>
>>
>>
>> I'm trying to do an insert of 3 entities that don't yet exist in the
>> db. All in all it should be very straightforward but it fails.
>>
>> public RentalMapping()
>> {
>> Not.LazyLoad();
>>
>> Id(o => o.Id).GeneratedBy.GuidComb();
>> Map(o => o.OrderDate).Not.Nullable();
>> References(o => o.Employee).Not.Nullable();
>> References(o => o.Customer).Not.Nullable();
>> HasMany(o => o.RentalItems)
>> .AsList(index => index.WithColumn("ListIndex")
>> .WithType<int>());
>> }
>>
>> public RentalItemMapping()
>> {
>> Not.LazyLoad();
>>
>> Id(oi => oi.Id).GeneratedBy.Assigned();
>> Map(oi => oi.Quantity).Not.Nullable();
>> References(oi => oi.Movie).Not.Nullable();
>> }
>>
>> rental.RentalItems = new[]
>> {
>> new RentalItem {Movie =
>> firstMovie, Quantity = 1},
>> new RentalItem {Movie =
>> secondMovie, Quantity = 2},
>> };
>>
>> repository.Save(rental);
>>
>>
>> NHibernate: SELECT this_.Id as Id1_0_, this_.City as City1_0_,
>> this_.LastName
>> NHibernate: SELECT this_.Id as Id0_0_, this_.LastName as LastName0_0_,
>> this_.F
>> NHibernate: SELECT this_.Id as Id2_0_, this_.RentalPrice as
>> RentalPr2_2_0_, th
>> NHibernate: SELECT this_.Id as Id2_0_, this_.RentalPrice as
>> RentalPr2_2_0_, th
>> NHibernate: INSERT INTO [Rental] (OrderDate, Employee_id, Customer_id,
>> Id) VAL
>> NHibernate: UPDATE [RentalItem] SET Rental_id = @p0, ListIndex = @p1
>> WHERE Id
>> failed: NHibernate.StaleStateException : Unexpected row count: 0;
>> expected: 1
>>
>> It has to fail obviously because NH is not inserting the RentalItems
>> at all. What is the correct way of handling this scenario?
>>
>> Tom
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---