Eric,

Thanks for the suggestion, but I just spent the last 10 minutes
googling "Formula", and couldn't make heads or tails of the examples I
found.

Could you :

- give me a sample formula (or point me to a good example)
- tell me exactly where I need to place the formula (in
CreateSessionFactory? In a new method I have to write?, etc)

Sorry to ask for so much hand holding, but I'm starting to think I
need to have an in-depth knowledge of NHibernate, Fluent NHIbernate,
and relational databases before I can do any real work with
Automapping.

This kind of defeats the whole idea of Automapping, in my mind.  Maybe
my expectations were unreasonable, but I thought the point of
Automapping was to just design your object model (within certain
contraints dictated by FNH), and the automapping would hide all the
ugly object-to-relational details.

Don't get me wrong, it's great when everything works - not having to
explicitly load and save every column, having cascading saves, etc.
But I'm finding it a real chore to get my classes to map, and I'm not
doing anything out of the ordinary from an OO perspective (at least I
don't think so... multiple lists of the same type in an Entity, lists
of floats, etc)

Anyway, sorry for venting, and I'm grateful for any help you can give
me.

Thanks again,

-Tom

On Nov 20, 5:33 pm, Eric Ridgeway <[email protected]> wrote:
> Forgot to mention that you need to use a Formula(or the like) to
> differentiate managers from employees to the two lists.
>
> --AF
>
>
>
> On Fri, Nov 20, 2009 at 2:31 PM, Eric Ridgeway <[email protected]> wrote:
> > Long story short.... the lists are all filled with the same Employee in
> > that store when you "rehydrate" them because there is nothing to
> > differentiate which Employees are Managers and and just plain employees...
> > there are several ways to handle that...
>
> >    public class Employee
> >    {
> >        public virtual int Id { get; private set; }
> >        public virtual string FirstName { get; set; }
> >        public virtual string LastName { get; set; }
> >        public virtual bool IsManager {get; set;}
>
> >    }
>
> >    public class Store
> >    {
> >        public virtual int Id { get; private set; }
> >        public virtual IList<Employee> Staff { get; private set; }
> >        public virtual IList<Employee> Managers { get; private set; }
>
> >        public void AddManager(Employee employee){
> >            employee.IsManager = true;
> >            this.Managers.Add(employee);
> >       }
>
> >        public void AddEmployee(Employee employee){
> >            this.Employees.Add(employee);
> >       }
>
> >    }
>
> > just a rough start (its not perfect) to get you headed in the right
> > direction....
> > hope it helps a little
>
> > --AF
>
> > On Fri, Nov 20, 2009 at 1:16 PM, tbushell <[email protected]> wrote:
>
> >> It appears that NHibernate cannot automap more than one IList of a
> >> given type in an entity.
>
> >> Consider the following two entities (based on the
> >> Examples.FirstProject sample code that is included with the Fluent
> >> NHibernate source code).
>
> >>    public class Employee
> >>    {
> >>        public virtual int Id { get; private set; }
> >>        public virtual string FirstName { get; set; }
> >>        public virtual string LastName { get; set; }
> >>    }
>
> >>    public class Store
> >>    {
> >>        public virtual int Id { get; private set; }
> >>        public virtual IList<Employee> Staff { get; set; }
> >>        public virtual IList<Employee> Managers { get; set; }
> >>    }
>
> >> This seems to be a perfectly valid object model - each store has
> >> several staff employees and several manager employees.
>
> >> But when I automap, the Staff and Managers lists are stored in the
> >> Employee table,all with the same foreign key.
>
> >>    Employee Table
>
> >>    Id FirstName LastName Store_id
> >>    3  Daisy     Harrison   1
> >>    4  Jack      Torrance   1
> >>    5  Sue       Walkters   1
> >>    6  Tom       Tommorow   1
> >>    7  Dick      Diggler    1
>
> >> The net result is that when the data is read back out of the database,
> >> both Staff and Managers lists are populated with **every** row in the
> >> table.
>
> >> This looks like a bug in Automapping to me, but I'm fairly new to
> >> NHibernate in any form, and don't fully know it's limitations yet.
>
> >> In any case, how can I make NHibernate treat the two lists as
> >> distinct?
>
> >> If possible, I'd appreciate an Automapping code fragment that directly
> >> addresses the sample code I've provided (e.g. something like "put this
> >> exact override in the .Mappings section of your
> >> CreateSessionFactory").
>
> >> This is because I'm only somewhat familiar with Automapping, and not
> >> at all familiar with the older ways of doing things, which means I
> >> can't "fill in the blanks" very well yet.
>
> >> But if you only have time to point me in the right direction, that
> >> would be helpful too.
>
> >> Here's my CreateSessionFactory code, to give some context:
>
> >>        private static ISessionFactory CreateSessionFactory()
> >>        {
> >>            ISessionFactory sessionFactory = null;
>
> >>            const string autoMapExportDir = "AutoMapExport";
> >>            if( !Directory.Exists(autoMapExportDir) )
> >>                Directory.CreateDirectory(autoMapExportDir);
>
> >>            try
> >>            {
> >>                var autoPersistenceModel =
> >>                    AutoMap.AssemblyOf<Product>()
> >>                            .Where(t => t.Namespace ==
> >> "Examples.FirstProject.Entities")
> >>                            .Conventions.Add( DefaultCascade.All() )
> >>                    ;
>
> >>                sessionFactory = Fluently.Configure()
> >>                    .Database(SQLiteConfiguration.Standard
> >>                                  .UsingFile(DbFile)
> >>                                  .ShowSql()
> >>                             )
> >>                    .Mappings(m => m.AutoMappings.Add
> >> (autoPersistenceModel)
> >>                                                 .ExportTo
> >> (autoMapExportDir)
> >>                             )
> >>                    .ExposeConfiguration(BuildSchema)
> >>                    .BuildSessionFactory()
> >>                    ;
> >>            }
> >>            catch (Exception e)
> >>            {
> >>                Console.WriteLine(e);
> >>            }
>
> >>            return sessionFactory;
> >>        }
>
> >> --
>
> >> 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]<fluent-nhibernate%2bunsubscr­[email protected]>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/fluent-nhibernate?hl=.- Hide quoted text -
>
> - Show quoted text -

--

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=.


Reply via email to