Thanks James. That should do what I need! J
From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: quinta-feira, 29 de Janeiro de 2009 22:35 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method Luis: I've just committed a change that'll affect this. I've added LazyLoad to subclass, and I've updated everything to use a Not property instead of explicit NotXXX methods; that way we won't forget about doing a Not something in the future. So it's now: LazyLoad() and Not.LazyLoad(), these are available wherever LazyLoad was before, and also on the subclass. On Tue, Jan 27, 2009 at 12:43 PM, Luis Abreu <lab...@gmail.com> wrote: Yeah, and if i recall correctly, the default is lazy loading, which is not working for meJ Thanks again. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:36 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method That sounds correct, although there should be a NotLazyLoaded method. By not setting any lazy load, FNH leaves the attribute off all together; this makes it fall back onto NHibernate's defaults. I shall add that method to my list of changes. On Tue, Jan 27, 2009 at 12:33 PM, Luis Abreu <lab...@gmail.com> wrote: Oh, just remembered…and what about the lazy attribute on the other properties (references)? For instance, on collections…I see there is a LazyLoad method but there isn't a NoLazyLoad method. So, I assumed that if I don't call that method I wouldn't get lazy loading and would get the lazy="false" on the roperty mapping. This isn't happening. Any reason for that? Thanks again Luis From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:26 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method Excellent! Glad we got there in the end. On Tue, Jan 27, 2009 at 12:23 PM, Luis Abreu <lab...@gmail.com> wrote: James, thanks for your time! As always, the mistake was mine: the error were coming from the snapshot classes which also had inheritance. Thanks again. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:12 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method That looks right to me, and you have NotLazyLoaded set on the main class too? In my setup I've got default-lazy to true, the parent class set to false, and all the subclasses also set to false. That works for me. On Tue, Jan 27, 2009 at 12:08 PM, Luis Abreu <lab...@gmail.com> wrote: I'm seeing the lazy="false" on the XML but I'm still getting the same error if I don't set the default-lazy to false. Btw, here's the mapping of one of the subclasses: DiscriminateSubClassesOnColumn("TipoEntidade", (Int32) (EntityKind.Single)) .SubClass<Individual>((Int32) (EntityKind.Single), e => { e.Map(ind => ind.BirthDate, "DataNascimento"); e.Component<BIInfo>(ind => ind.BIInfo, bi => { bi.Map(b => b.Archive, "Arquivo") .WithLengthOf(100); bi.Map(b => b.EmissionDate, "DataEmissao") .WithLengthOf(50); bi.Map(b => b.Number, "BI") .WithLengthOf(20); }); e.SetAttribute( "lazy", "false" ); }) .SubClass<Company>((Int32)(EntityKind.Company), e => e.SetAttribute("lazy", "false") ); See anything wrong? Thanks. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 11:49 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method You didn't mention it was a subclass that was failing! Subclasses also have their own lazy attribute as well as their parent class, and I can now see we haven't mapped a way to handle this in FNH. You SHOULD do something like this (but can't right now): DiscriminateSubClassesOnColumn("TipoEntidade") .SubClass<Individual>(subclass => { subclass.Map(...); subclass.NotLazyLoaded(); }); However, as you can't do that currently, you can use SetAttribute instead. subclass.SetAttribute("lazy", "false"); I'll look into getting this implemented properly. Let me know if the set attribute hack works. On Tue, Jan 27, 2009 at 11:36 AM, Luis Abreu <lab...@gmail.com> wrote: Hello again. You're not going to like this answer... it works for me! Yep, I don't like that answer :) Ok, back to my code. First, I'm not using sessionsource because the assembly is not signed and since it has dependencies on non-signed assemblies I cannot sign it here. So, I'm just getting the XML from the mappings by using code similar to this: var currentTypes = GetType().Assembly.GetTypes(); var methodsThatReturnXmlDocs = currentTypes .Where(existingType => GetMethodForExecution(existingType) != null) .Select(existingType => GetMethodForExecution(existingType)) .ToList(); foreach (var method in methodsThatReturnXmlDocs) { var mappingVisitor = new MappingVisitor(); mappingVisitor.Conventions.DefaultLazyLoad = false; //HAD TO ADD THIS var doc = method(mappingVisitor); configuration.AddDocument(doc); } Ok, here's the XML my mappings are generating: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" assembly="Sra.Core.Entities" namespace="Sra.Core.Entities"> <class name="Entity" table="Entidades" xmlns="urn:nhibernate-mapping-2.2" lazy="false" discriminator-value="0"> <id name="Id" column="IdEntidade" type="Int32" unsaved-value="0"> <generator class="identity" /> </id> <discriminator column="TipoEntidade" type="Int32" /> <version column="Version" name="Version" /> <property name="Name" column="Nome" length="200" type="String" not-null="true"> <column name="Nome" /> </property> <property name="Nif" column="NIF" length="9" type="String" not-null="true"> <column name="NIF" /> </property> <property name="Nifap" column="Nifap" length="50" type="String" not-null="true"> <column name="Nifap" /> </property> <many-to-one cascade="save-update" name="Action" column="IdAccao" /> <set name="Branches" access="field.camelcase-underscore" cascade="all"> <key column="IdEntidade" /> <one-to-many class="Sra.Core.Entities.Branch, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" /> </set> <subclass name="Sra.Core.Entities.Company, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" discriminator-value="1" /> <subclass name="Sra.Core.Entities.Individual, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" discriminator-value="0"> <property name="BirthDate" column="DataNascimento"> <column name="DataNascimento" /> </property> <component name="BIInfo" insert="true" update="true"> <property name="Number" column="BI" length="20" type="String"> <column name="BI" /> </property> <property name="EmissionDate" column="DataEmissao" length="50" type="String"> <column name="DataEmissao" /> </property> <property name="Archive" column="Arquivo" length="100" type="String"> <column name="Arquivo" /> </property> </component> </subclass> </class> </hibernate-mapping> Now here's the XML when I don't set the default lazy convention (which means it's set to true by default, right?): <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" assembly="Sra.Core.Entities" namespace="Sra.Core.Entities"> <class name="Entity" table="Entidades" xmlns="urn:nhibernate-mapping-2.2" lazy="false" discriminator-value="0"> <id name="Id" column="IdEntidade" type="Int32" unsaved-value="0"> <generator class="identity" /> </id> <discriminator column="TipoEntidade" type="Int32" /> <version column="Version" name="Version" /> <property name="Name" column="Nome" length="200" type="String" not-null="true"> <column name="Nome" /> </property> <property name="Nif" column="NIF" length="9" type="String" not-null="true"> <column name="NIF" /> </property> <property name="Nifap" column="Nifap" length="50" type="String" not-null="true"> <column name="Nifap" /> </property> <many-to-one cascade="save-update" name="Action" column="IdAccao" /> <set name="Branches" access="field.camelcase-underscore" cascade="all"> <key column="IdEntidade" /> <one-to-many class="Sra.Core.Entities.Branch, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" /> </set> <subclass name="Sra.Core.Entities.Company, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" discriminator-value="1" /> <subclass name="Sra.Core.Entities.Individual, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac" discriminator-value="0"> <property name="BirthDate" column="DataNascimento"> <column name="DataNascimento" /> </property> <component name="BIInfo" insert="true" update="true"> <property name="Number" column="BI" length="20" type="String"> <column name="BI" /> </property> <property name="EmissionDate" column="DataEmissao" length="50" type="String"> <column name="DataEmissao" /> </property> <property name="Archive" column="Arquivo" length="100" type="String"> <column name="Arquivo" /> </property> </component> </subclass> </class> </hibernate-mapping> And in here's the exception I'm getting whenever I set lazy to false: NHibernate.InvalidProxyTypeException: The following types may not be used as proxies: Sra.Core.Entities.Individual: method SetName should be virtual Etc, etc, etc for all the properties of my class. Should I get this exception? At first sight, it sseems like the only thing that changed is the default-lazy attribute, but I could be missing something... Oh, and btw, I've just noticed that I'm not getting a lazy=false on my collections. I'm expecting this because the only option I have on my method chain when defining the collection mappings is the LazyLoad method call... Thanks again. Luis --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---