Richard,
I've attempted to replicate your problem and failed, can you provide us with
some more context? The smallest example to recreate the problem would be
useful.

FYI, this is what I tested with (based on the latest master commit):

    [TestFixture]
    public class HasManyConventionTests
    {
        [Test]
        public void ShouldBeAbleToSpecifyKeyColumnNameInConvention()
        {
            var model =
                AutoMap.Source(new StubTypeSource(typeof(Target)))
                    .Conventions.Add<HasManyConvention>();

            model.CompileMappings();

            model.BuildMappings()
                .First()
                .Classes.First()
                .Collections.First()
                .Key.Columns.First().Name.ShouldEqual("xxx");

        }

        private class HasManyConvention : IHasManyConvention
        {
            public void Apply(IOneToManyCollectionInstance instance)
            {
                instance.Key.Column("xxx");
            }
        }
    }

    internal class Target
    {
        public IList<Child> Children { get; set; }
    }

    internal class Child
    { }

On Thu, Aug 20, 2009 at 10:08 AM, Richard Evans
<[email protected]>wrote:

>
> Hi James
>
> Thanks for your suggestion. I tried this and it didn't work. Code
> below shows the state of things. It is as though the call to
> instance.Key.Column("ParentId"); is not having any effect.
>
> public void Apply(IOneToManyCollectionInstance instance)
>        {
>             bool containsGroupId = instance.Key.Columns.Contains
> ("GroupId");  // true
>
>            instance.Key.Column("ParentId");
>
>            bool containsParentId = instance.Key.Columns.Contains
> ("ParentId");  // false
>            containsGroupId = instance.Key.Columns.Contains
> ("GroupId");   // true
>        }
>
> I've got a work around in place, see following code (Add("ParentId")
> that does work.
>
> model.ForTypesThatDeriveFrom<Group>(map =>
>                            {
>                                map.Where("IsDeleted=0");
>                                map.Table("Group_");
>                                map.HasMany(x => x.Children)
>                                    .Cascade.Delete()
>                                    .Inverse()
>                                    .Access.CamelCaseField
> (Prefix.Underscore)
>                                    .KeyColumns.Add("ParentId");
>                                map.References(x => x.Parent);
>                            });
>
> On Aug 19, 2:05 pm, James Gregory <[email protected]> wrote:
> > instance.Key.Column("ParentId") should do the trick
> > On Wed, Aug 19, 2009 at 2:01 PM, Richard Evans <
> [email protected]>wrote:
> >
> >
> >
> > > Thanks James for your suggestion, I have that working now.
> >
> > > I've just got one last convention that I need to port.  I've got half
> > > way but am stuck when it comes to the column names. I've tried
> > > intellisensing and looking at the API but nothing springs to mind.
> > > Should I be using a different convention for this type of
> > > functionality?
> >
> > > public class SelfReferencingHasManyConvention : IHasManyConvention
> > >    {
> > >        public bool Accept(IOneToManyPart target)
> > >        {
> > >            return target.Member.ReflectedType == target.EntityType &&
> > > target.Member.Name == "Children";
> > >        }
> >
> > >        public void Apply(IOneToManyPart target)
> > >        {
> > >            target.KeyColumnNames.Clear();
> > >            target.KeyColumnNames.Add("ParentId");
> > >        }
> > >    }
> >
> > > public class SelfReferencingHasManyConvention : IHasManyConvention,
> > > IHasManyConventionAcceptance
> > >    {
> > >        public void Accept
> > > (IAcceptanceCriteria<IOneToManyCollectionInspector> criteria)
> > >        {
> > >            criteria.Expect(x => (x.Member.ReflectedType ==
> > > x.EntityType && x.Member.Name == "Children"));
> > >        }
> >
> > >        public void Apply(IOneToManyCollectionInstance instance)
> > >        {
> > >            instance.
> > >         }
> > >    }
> >
> > > On Aug 19, 11:26 am, James Gregory <[email protected]> wrote:
> > > > I should've caught that in the first place, but your original
> convention
> > > > threw me. You'd never have a ClassMap<Enum>, so you'd never have a
> > > > IClassConvention for one.
> >
> > > > On Wed, Aug 19, 2009 at 11:25 AM, James Gregory <
> [email protected]
> > > >wrote:
> >
> > > > > I just had a look at that code, it's using the wrong convention.
> > > > > IPropertyConvention is what you'll need, and in that case you'd use
> > > > > CustomType for changing it's type.
> >
> > > > > On Wed, Aug 19, 2009 at 10:41 AM, Richard Evans <
> > > [email protected]
> > > > > > wrote:
> >
> > > > >> Okay, just tried this and it doesn't compile, there is no setter
> for
> > > > >> EntityType on IClassInstance.
> >
> > > > >> I'll have a dig around and see if there is a different way.
> >
> > > > >> Cheers.
> >
> > > > >> On Aug 18, 11:04 pm, Jim Tanner <[email protected]> wrote:
> > > > >> > No problem, glad to have benn helpfull.
> >
> > > > >> > On 18 août, 22:57, Richard Evans <[email protected]>
> wrote:
> >
> > > > >> > > i did try but i never thought to implement the
> > > > >> > > IClassConventionAcceptance interface. It was obvious that
> there
> > > was a
> > > > >> > > method missing from the interface but I couldn't work out
> which
> > > > >> > > interface I needed to implement. It's obvious now.
> >
> > > > >> > > Thanks for the suggestion and code sample, much appreciated.
> >
> > > > >> > > On Aug 18, 4:41 pm, Jim Tanner <[email protected]> wrote:
> >
> > > > >> > > > I had the same problem yesterdayhttp://
> > > > >> groups.google.com/group/fluent-nhibernate/browse_thread/thread...
> >
> > > > >> > > > Try this
> >
> > > > >> > > > public class
> EnumerationTypeShouldBeIntegerNotStringConvention
> > > > >> > > >   : IClassConvention, IConventionAcceptance<IClassInspector>
> > > > >> > > >     {
> > > > >> > > >         public void
> Accept(IAcceptanceCriteria<IClassInspector>
> > > > >> > > > criteria)
> > > > >> > > >         {
> > > > >> > > >             criteria.Expect(x => x.GetType() ==
> typeof(Enum));
> > > > >> > > >         }
> >
> > > > >> > > >         void IConvention<IClassInspector,
> IClassInstance>.Apply
> > > > >> > > > (IClassInstance instance)
> > > > >> > > >         {
> > > > >> > > >             instance.EntityType = typeof(int);
> > > > >> > > >         }
> > > > >> > > >     }
> >
> > > > >> > > > Documentation can be found herehttp://
> > > > >> wiki.fluentnhibernate.org/Conventions
> > > > >> > > > and herehttp://
> > > > >> wiki.fluentnhibernate.org/Conventions#Conditional_applying_of_...
> >
> > > > >> > > > On 18 août, 16:29, Richard Evans <[email protected]
> >
> > > wrote:
> >
> > > > >> > > > > We've got a convention that I'd like to port to RC1. Any
> > > > >> suggestions
> > > > >> > > > > for the best way to migrate this?
> >
> > > > >> > > > > public class
> EnumerationTypeShouldBeIntegerNotStringConvention
> > > :
> > > > >> > > > > IClassConvention
> > > > >> > > > >     {
> > > > >> > > > >         public bool Accept(IClassMap target)
> > > > >> > > > >         {
> > > > >> > > > >             return target.GetType() == typeof(Enum);
> > > > >> > > > >         }
> >
> > > > >> > > > >         public void Apply(IClassMap target)
> > > > >> > > > >         {
> > > > >> > > > >             target.SetAttribute("type", "int");
> > > > >> > > > >         }
> >
> > > > >> > > > > }
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to