Got the same issue.Here is my mapping:
public SubscriptionMap()
{
Id(x => x.Id, "SubscriptionId");
Map(x => x.Name,
"Name").WithLengthOf(50).Unique().Not.Nullable();
Map(x => x.ContactEmailAddress,
"ContactEmailAddress").WithLengthOf(50).Not.Nullable();
HasMany(x => x.SubscriptionDefinitions)
.Inverse().KeyColumnNames.Add("SubscriptionId").AsBag().Cascade.All();
}
public SubscriptionDefinitionMap()
{
Id(x => x.Id, "SubscriptionDefinitionId");
References(x => x.Subscription,
"SubscriptionId").FetchType.Join();
JoinedSubClass<MessagingSubscriptionDefinition>("SubscriptionDefinitionId",
part => {
part.Map(m =>
m.QueueName).Unique().WithLengthOf(50).Not.Nullable();
part.Map(m => m.MessageLifeSpanInSeconds);
part.Map(m => m.UseBinaryFormatter);
});
}
When I look @ the test I see that we are creating instances of the
SubscriptionDefinition but that we haven't wired up the bi-directional
relationship.
How is that done with this type of test?
Greg
On Wed, Mar 25, 2009 at 10:53 AM, James Gregory <[email protected]>wrote:
> Hmm, that's pretty odd. Try setting a Cascade.All on
> Subscription.SubscriptionDefinitions
>
>
> On Wed, Mar 25, 2009 at 4:48 PM, Greg Cook <[email protected]> wrote:
>
>> Thanks for the quick reply... I've added the bi-directional relationship
>> between Subscription -0...*- SubscriptionDefinition and have a mapping test
>> that proves it works.
>> Below is the PersistenceSpecification version of a mapping test that is
>> failing with the following message:
>> It appears as though I don't have the relationship between the collection
>> and the parent.
>> What do I need to do in order to have this work? Thanks again..
>>
>> I thought I followed the pattern for this type of test based on the blogs
>> I saw...
>>
>> NHibernate:
>>
>> INSERT INTO dbo.[SubscriptionDefinition] (LastModifiedDate, Version,
>> CreateBy, CreateDate, LastModifiedBy, SubscriptionId) VALUES (@p0, @p1, @p2,
>> @p3, @p4, @p5);
>>
>> select SCOPE_IDENTITY(); @p0 = '2009/03/25 10:44:30 AM', @p1 = '1', @p2 =
>> 'gcook', @p3 = '2009/03/25 10:44:30 AM',
>> @p4 = 'gcook', @p5 = ''
>>
>> System.Data.SqlClient.SqlException:
>> Cannot insert the value NULL into column 'SubscriptionId', table
>> 'xxx.dbo.SubscriptionDefinition'; column does not allow nulls. INSERT fails
>> .
>> The statement has been terminated.
>>
>> [Test]
>> public void SubscriptionWithSubscriptionDefinitions()
>> {
>> var definitions =
>> new List<SubscriptionDefinition>
>> {
>>
>> ObjectMother.CreateMessagingSubscriptionDefinition("foo"),
>>
>> ObjectMother.CreateMessagingSubscriptionDefinition("bar"),
>>
>> ObjectMother.CreateMessagingSubscriptionDefinition("another 1")
>> };
>> new PersistenceSpecification<Subscription>(session)
>> .CheckProperty(x => x.Name, "Apple")
>> .CheckProperty(x => x.ContactEmailAddress, "
>> myemailaddresss.com")
>> .CheckList(x => x.SubscriptionDefinitions, definitions)
>> .VerifyTheMappings();
>> }
>>
>> //THIS TEST WORKS
>> [Test]
>> public void CanHaveSubscriptionDefinitions()
>> {
>> Subscription subscription =
>> ObjectMother.CreateSubscription("mySub").Save<Subscription>();
>>
>> subscription.Add(ObjectMother.CreateMessagingSubscriptionDefinition("Q1"));
>>
>> subscription.Add(ObjectMother.CreateMessagingSubscriptionDefinition("Q2"));
>>
>> subscription.Add(ObjectMother.CreateMessagingSubscriptionDefinition("Q3"));
>>
>> DataSource.Flush().ClearAllCaches();
>>
>> Subscription found =
>> DataSource.FindById<Subscription>(subscription.Id);
>> Assert.IsNotNull(found);
>> Assert.AreEqual(3, found.SubscriptionDefinitions.Count);
>>
>> foreach (SubscriptionDefinition each in
>> subscription.SubscriptionDefinitions)
>> {
>>
>> Assert.IsTrue(found.SubscriptionDefinitions.Contains(each));
>> }
>> }
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---