Forgot to mention that the database is setting the IDs of the objects,
maybe this is also a problem for nhibernate?

On 15 Sep., 17:13, griti <gritiba...@gmail.com> wrote:
> Thanks for the input, now it's storing the fk as expected for Log ->
> LogEntry.
>
> For this case I don't need any reference back from the child.
>
> When I remove .Inverse(), I get the following error:
> [InvalidOperationException: Collection was modified; enumeration
> operation may not execute.]
>
> What I do: Load an existing Log, add a new LogEntry and there I add a
> new LogEntryValue. Now I would like to save the Log again and have
> LogEntry and LogEntryValue saved. Is this only possible with a
> reference back to the parents?
>
> Regards
>
> On 15 Sep., 16:33, Hudson Akridge <hudson.akri...@gmail.com> wrote:
>
>
>
> > You have .Inverse() marked on all of your OTM collections, but do not have a
> > reference back from the child side to the parent in the mapping using a
> > References(). In that case, an inverse is not what you'd want to set up on
> > the OTM.
> > Although, if a bi-directional is what you're looking for, then you will need
> > a reference back to the parent from the child.
>
> > On Tue, Sep 15, 2009 at 8:33 AM, griti <gritiba...@gmail.com> wrote:
>
> > > Hi there
>
> > > I am working in a prototype with fluent nhibernate 1.0 and nhibernate
> > > 2.1. So far the rules seemed logical to me. But now I have some kind
> > > of troubles getting the fk of the parent to the child's table.
>
> > > I have 3 tables(simplified):
>
> > > Log:
> > > -ID
> > > -Type
>
> > > LogEntry:
> > > -ID
> > > -Log_Id
> > > -Action
>
> > > LogEntryValues:
> > > -ID
> > > -LogEntry_Id
> > > -Value
>
> > > The classes are quite simple, Log and LogEntry have each a a iList of
> > > their childs which can be null.
>
> > > The mapping looks like this:
> > > public class LogMap : ClassMap<Log>
> > >    {
> > >        LogMap()
> > >        {
> > >            LazyLoad();
> > >            Id(x => x.Id);
> > >            Map(x => x.Type);
> > >            HasMany(x => x.LogEntries).Inverse().Cascade.All();
> > >        }
> > >    }
>
> > >    public class LogEntryMap : ClassMap<LogEntry>
> > >    {
> > >        LogEntryMap()
> > >        {
> > >            LazyLoad();
> > >            Id(x => x.ID);
> > >            Map(x => x.action).CustomType(typeof
> > > (Enumerations.Enumerators.DatabaseActions));
> > >            HasMany(x => x.LogValues).Inverse().Cascade.All();
> > >        }
> > >    }
>
> > >    public class LogEntryValuesMap : ClassMap<LogEntryValues>
> > >    {
> > >       LogEntryValuesMap()
> > >        {
> > >            LazyLoad();
> > >            Id(x => x.ID);
> > >            Map(x => x.Value);
> > >            ReadOnly();
> > >        }
> > >    }
>
> > > What I think might be wrong is the configuration of fluent nhibernate:
> > > private static ISessionFactory SessionFactory
> > >        {
> > >            get
> > >            {
> > >                if (sessionFactory == null)
> > >                {
>
> > >                    try
> > >                    {
> > >                        String luceneIndexPath =
> > > AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
> > > @"\Lucene_index";
> > >                        if (!System.IO.Directory.Exists
> > > (luceneIndexPath))
> > >                            System.IO.Directory.CreateDirectory
> > > (luceneIndexPath);
>
> > >                        sessionFactory = Fluently.Configure()
> > >                                        .Database
> > > (MsSqlConfiguration.MsSql2005
> > >                                                .ConnectionString(c =>
> > > c.Is(connectionString))
> > >                                                .ShowSql()
> > >                                                .ProxyFactoryFactory
> > > ("NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
> > > NHibernate.ByteCode.LinFu "))
> > >                                            .Mappings(m =>
> > > m.FluentMappings.AddFromAssemblyOf<AxendoAnmeldung>())
> > >                                            .ExposeConfiguration(x =>
> > >                                                {
> > >                                                    //
> > > NHibernate.Search Config
> > >                                                    //x.SetProperty
> > > ("hibernate.search.default.directory_provider", typeof
> > > (RAMDirectoryProvider).AssemblyQualifiedName);
>
> > >                                                    x.SetProperty
> > > ("hibernate.search.default.directory_provider", typeof
> > > (FSDirectoryProvider).AssemblyQualifiedName);
> > >                                                    x.SetProperty
> > > ("hibernate.search.default.indexBase", luceneIndexPath);
>
> > >                                                    //NHibernate
> > > Config
> > >                                                    x.SetProperty
> > > ("current_session_context_class", "web");
> > >                                                })
> > >                                          .BuildSessionFactory();
> > >                    }
> > >                    catch (Exception ex)
> > >                    {
> > >                        throw ex;
> > >                    }
> > >                }
> > >                return sessionFactory;
> > >            }
> > >        }
>
> > > My Database is MS SQL Server 2005, the fk's are set to their
> > > corresponding parent-ids.
>
> > > Any hints what's missing?
>
> > > Regards
>
> > --
> > - Hudsonhttp://www.bestguesstheory.comhttp://twitter.com/HudsonAkridge
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to