[fluent-nhib] PersistenceSpecification and the CheckList issue
Hello guys. I've asked about this in the past, but I didn't get a definitive answer. Here's my scenario: I've got a one-to-many mappings where each side is represented by an entity (not a component). Can anyone tell me why CheckList insists on inserting the items on the many side before inserting the item on the one side? I mean, for it work I need to make the foreign key accept null values because if I don't, I'll end up with an SQL exception. Instead of putting here the code, I'll just put a link to an old post which has some code that shows the problem: http://www.mail-archive.com/fluent-nhibernate@googlegroups.com/msg07492.html ok, so is this a bug? If it is, does anyone know if it will be fixed? btw, I'm asking if this is a bug because the code does insert when running it through a transaction which gets committed... thanks and regards, 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.
[fluent-nhib] still on the CheckList method and on how things are tested in PersistenceSpecification
Hello again guys. I'm sorry, but I'm still a little lost on how PersistenceSpecification does its testing when it uses collections. Ok, I've got a collection mapping between Individual and Branches (Individual is stored in a table called Entidades and Branch is stored in a Filiais table, where IdEntidade is a foreign key). I'm using something like this to test the mappings: new PersistenceSpecificationOcorrencia(session) .CheckProperty(e = e.Nif, _nif) .CheckProperty( e =e.Organismo, organismo) .CheckProperty( e = e.Descricao, _descricao) .CheckProperty( e = e.TipoOcorrencia, TipoOcorrencia.Processo) .CheckList( e =e.Intervencoes, intervencoes, ( o, i) = o.ModificaEstado(i)) .VerifyTheMappings(); Now, the problem happens in the CheckList method. Here's the SQL it's running (I've cleaned it a little bit and I'm just putting the generated SQL): INSERT INTO Filiais (Endereco, CodigoPostal, IdFreguesia, NIF, Nome, NomeRepresentante, IdEntidade) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6); select SCOPE_IDENTITY();@p0 = 'Some street', @p1 = '-000 somewhere', @p2 = 1931, @p3 = '123456789', @p4 = 'Test branch', @p5 = NULL, @p6 = NULL INSERT INTO Entidades (Version, Nome, NIF, Nifap, IdAccao, Arquivo, DataEmissao, BI, DataNascimento, TipoEntidade) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, 0); select SCOPE_IDENTITY();@p0 = 1, @p1 = 'Luis', @p2 = '123456789', @p3 = '12345', @p4 = 3499, @p5 = 'Funchal', @p6 = '10/10/2009', @p7 = '123123', @p8 = NULL INSERT INTO LoginInfo (Activado, DataActivacao, Hash, Salt, NomeUtilizador, EmailNotificacao, IdEntidade) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6); select SCOPE_IDENTITY();@p0 = True, @p1 = 07-07-2010 12:20:19, @p2 = 0x7D2A84DA92DB699E94AE7E42E3FC4211C53871377DFFACE74D54F76A0A4BAA78, @p3 = 0x456ADDE3A5B19A516BD72100D588E66AAA1F2DA7BB4668947E0F618927F3EA74, @p4 = 'something', @p5 = 'some...@maiil.pt', @p6 = 3604 UPDATE Filiais SET Endereco = @p0, CodigoPostal = @p1, IdFreguesia = @p2, NIF = @p3, Nome = @p4, NomeRepresentante = @p5, IdEntidade = @p6 WHERE IdFilial = @p7;@p0 = 'Some street', @p1 = '-000 somewhere', @p2 = 1931, @p3 = '123456789', @p4 = 'Test branch', @p5 = NULL, @p6 = 3604, @p7 = 4220 UPDATE Filiais SET IdEntidade = @p0 WHERE IdFilial = @p1;@p0 = 3604, @p1 = 4220 Why does it do this? I mean, if IdEntidade is foreign key, then that means I can't pass null to the IdEntidade in Filiais. But since Filiais is inserted before Entidades, that means getting a SQL exception when the test is run. If I remove the foreign key (which I did to get the complete SQL list), the test passes. But I really don't want to remove that foreign key (in fact, I've run the code in a form and NH does persist the item correctly in the presence of the foreign key). So, how am I supposed to use the CheckList method? thanks. -- Regards, Luis Abreu -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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.
Re: [fluent-nhib] PersistenceSpecification and CheckList
Hello Paul. Yes, I found that post :) Now, the thing is that my problem is still happening, so I'm not sure on what's going on...I'm probably doing something wrong, but don't know what... I've improved my code and now I'm using something like this for testing the collection: new PersistenceSpecificationOcorrencia(session) .CheckProperty(e = e.Nif, _nif) .CheckProperty( e =e.Organismo, organismo) .CheckProperty( e = e.Descricao, _descricao) .CheckProperty( e = e.TipoOcorrencia, TipoOcorrencia.Processo) .CheckList( e =e.Intervencoes, intervencoes, ( o, i) = o.ModificaEstado(i)) .VerifyTheMappings(); I expected that passing the action as 3rd parameter would be enough for making sure that Intervencao has its Ocorrencia property set (internally, the ModificaEstado method is responsible for adding Intervencao to the inner collection maintained by the Ocorrencia and for setting the Intervencao's Ocorrencia property to the Ocorrencia object over which the call is made). I've looked at the output and I've noticed that my code is generating the following SQL statements (I'monly putting there the statements related with Ocorrencia and Intervencao tables): INSERT INTO Accoes (DataAccao, Utilizador, Descricao, Aplicacao) VALUES (@p0, @p1, @p2, @p3); select SCOPE_IDENTITY();@p0 = 07-07-2010 14:16:51, @p1 = 'labreu', @p2 = 'This is just a test', @p3 = 'Test' INSERT INTO Organismos (Nome) VALUES (@p0); select SCOPE_IDENTITY();@p0 = 'Organismo teste' INSERT INTO Intervencoes (Version, Guid, TipoEstado, Observacoes, IdAccao, IdOcorrencias) VALUES (@p0, @p1, @p2, @p3, @p4, @p5); select SCOPE_IDENTITY();@p0 = 1, @p1 = 5d7750b5-1ae1-4b80-9f11-a84d00afc45d, @p2 = 0, @p3 = 'teste de intervenção', @p4 = 3808, @p5 = NULL And then, I get the exception: NHibernate.Exceptions.GenericADOException : could not insert: [Sra.Ocorrencias.Intervencao][SQL: INSERT INTO Intervencoes (Version, Guid, TipoEstado, Observacoes, IdAccao, IdOcorrencias) VALUES (?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()] System.Data.SqlClient.SqlException : Cannot insert the value NULL into column 'IdOcorrencias', table 'SRAEntidades.dbo.Intervencoes'; column does not allow nulls. INSERT fails. The statement has been terminated. This happens because IdOcorrencia is set up as a foreign key: If I remove the relationship between the 2 tables, then I've noticed that my test code ends up exeucting the previous instructions and then it executes another 2: * insert into Ocorrencias * performs an Update over the previous inserted Intervencao Is this the right behavior? In my opinion, Ocorrencias should be the first item saved into the db and only then should each Intervencao be saved. Am I wrong? I've built a small app which creates an Ocorrencia and it works fine when I try to save it to the database (and I checked and made sure that I had the relationship between the two tables when I run this small test). Does this mean that I'm missing something in my tests? Thanks Luis On Wed, Jul 7, 2010 at 12:51 PM, Paul Batum paul.ba...@gmail.com wrote: Not sure if I'm on the right track exactly, but there are some overloads for CheckList that might help you. See this thread: http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/cebc70ff873e4fd2/ce6cc622bc02d9c On Mon, Jul 5, 2010 at 6:30 PM, Luis Abreu lab...@gmail.com wrote: Hello guys, I've got the following mappings: public class OcorrenciaMapping: ClassMapSra.Ocorrencias.Ocorrencia { HasMany(ocorrencia = ocorrencia.Intervencoes) .Access.AsCamelCaseField(Prefix.Underscore) .AsBag() .Cascade .All() .KeyColumnNames.Add(IdOcorrencias) .Not.LazyLoad(); } public class IntervencaoMapping: ClassMapIntervencao { WithTable(Intervencoes); Not.LazyLoad(); Id(intervencao = intervencao.Id) .ColumnName(IdIntervencoes) .WithUnsavedValue(0) .SetGeneratorClass(identity); Map(intervencao = intervencao.Guid, Guid) .Not.Nullable(); Version(ent = ent.Version) .ColumnName(Version); References(ent = ent.Action, IdAccao) .Cascade .SaveUpdate(); Map(intervencao = intervencao.TipoEstado, TipoEstado) .CustomTypeIs(typeof (TipoEstado)) .CustomSqlTypeIs(integer); Map(intervencao = intervencao.Observacoes, Observacoes); References(intervencao = intervencao.Ocorrencia, IdOcorrencias) .Not.LazyLoad(); } Now, I'm trying to run the following test: var accao = CreateAction(); session.Save(accao); var organismo = CreateOrganismo(); session.Save(organismo); intervencao
[fluent-nhib] fluent nh wiki
Hello guys. I'm reading the wiki: http://wiki.fluentnhibernate.org/Fluent_mapping and I've got a question on the table-per-hierachy mapping shown at the end of the page.Don't you need to specify the discriminator value for each derived class? I'm not seein that on the example that is shown. thanks. -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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.
Re: [fluent-nhib] fluent nh wiki
Hello James. ah, I see. it's been a long time since I used fluent nh (in fact, it seems like my project was still running with a really old release) so I didn't notice that. I guess that explains the initial error I was getting which involved the name of the class. still regarding the docs, wouldn't it be better to add a note mentioning that so that guys like me (or others that are getting started) don't get lost while trying to use subclasses? just asking... thanks again On Tue, Jul 6, 2010 at 11:58 AM, James Gregory jagregory@gmail.com wrote: Nope, not if you don't want to. Discriminators default to using the class name as the discriminator value. On Tue, Jul 6, 2010 at 11:51 AM, Luis Abreu lab...@gmail.com wrote: Hello guys. I'm reading the wiki: http://wiki.fluentnhibernate.org/Fluent_mapping and I've got a question on the table-per-hierachy mapping shown at the end of the page.Don't you need to specify the discriminator value for each derived class? I'm not seein that on the example that is shown. thanks. -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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. -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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. -- Regards, Luis Abreu -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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.
[fluent-nhib] PersistenceSpecification and CheckList
Hello guys, I've got the following mappings: public class OcorrenciaMapping: ClassMapSra.Ocorrencias.Ocorrencia { HasMany(ocorrencia = ocorrencia.Intervencoes) .Access.AsCamelCaseField(Prefix.Underscore) .AsBag() .Cascade .All() .KeyColumnNames.Add(IdOcorrencias) .Not.LazyLoad(); } public class IntervencaoMapping: ClassMapIntervencao { WithTable(Intervencoes); Not.LazyLoad(); Id(intervencao = intervencao.Id) .ColumnName(IdIntervencoes) .WithUnsavedValue(0) .SetGeneratorClass(identity); Map(intervencao = intervencao.Guid, Guid) .Not.Nullable(); Version(ent = ent.Version) .ColumnName(Version); References(ent = ent.Action, IdAccao) .Cascade .SaveUpdate(); Map(intervencao = intervencao.TipoEstado, TipoEstado) .CustomTypeIs(typeof (TipoEstado)) .CustomSqlTypeIs(integer); Map(intervencao = intervencao.Observacoes, Observacoes); References(intervencao = intervencao.Ocorrencia, IdOcorrencias) .Not.LazyLoad(); } Now, I'm trying to run the following test: var accao = CreateAction(); session.Save(accao); var organismo = CreateOrganismo(); session.Save(organismo); intervencao = CreateIntervencao(); ((IHasAssignedDomainAction)intervencao).SetActionTo(accao); var intervencoes = new ListIntervencao {intervencao}; new PersistenceSpecificationOcorrencia(session) .CheckProperty(e = e.Nif, _nif) .CheckProperty( e =e.Organismo, organismo) .CheckProperty( e = e.Descricao, _descricao) .CheckProperty( e = e.TipoOcorrencia, TipoOcorrencia.Processo) .CheckList( e = e.Intervencoes, intervencoes) .VerifyTheMappings(); the problem is that I get an exception on the database saying that could not insert: [Sra.Ocorrencias.Intervencao][SQL: INSERT INTO Intervencoes (Version, Guid, TipoEstado, Observacoes, IdAccao, IdOcorrencias) VALUES (?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()] System.Data.SqlClient.SqlException : Cannot insert the value NULL into column 'IdOcorrencias', table 'SRAEntidades.dbo.Intervencoes'; column does not allow nulls. INSERT fails. The statement has been terminated. In my domain, Intevencao will only get added to the collection through a method which ensures that its Ocorrencia property is set. But I'm not sure if there's any way to do that with the CheckList method. Any clues? -- You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibern...@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.
[fluent-nhib] fluent mappings and filtering types.
Hello guys. I'm converting some old code I had which used mapping visitors to load and populate the Configurationn object. I was under the impression that this code: var configuration = Fluently.Configure( ) .Database( GetDatabaseInfo() ) .Mappings( m = m.FluentMappings.AddFromAssembly( assembly ) ) .ExposeConfiguration( config = SetupConfiguration( config ) ) .BuildConfiguration(); Should do the same thing. Btw, Getdatabaseinfo looks like this: protected virtual IPersistenceConfigurer GetDatabaseInfo( ) { return MsSqlConfiguration.MsSql2005 .ConnectionString( s = s.Is( _connectionString ) ) .ShowSql(); } And SetupConfiguration looks like this: protected override void SetupConfiguration(NHibernate.Cfg.Configuration configuration) { configuration.EventListeners.LoadEventListeners = new[] {new CustomLoadEventListener()}; } Now, the problem is that I'm getting this: MSBUILD : warning : Sra.Core.Entities.Repositories.Tests.CivilParishRepositoryLoadInexistentPari shById.Should_return_null_for_non_existing_parish: FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. MSBUILD : warning : MSBUILD : warning : MSBUILD : warning : System.ApplicationException : Error while trying to build the Mapping Document for 'Sra.Core.Entities.Entity' MSBUILD : warning : NHibernate.MappingException : (XmlDocument)(8,6): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'discriminator' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'property, many-to-one, one-to-one, component, dynamic-component, any, map, set, list, bag, idbag, array, primitive-array, join, subclass, joined-subclass, union-subclass, loader, sql-insert, sql-update, sql-delete, filter' in namespace 'urn:nhibernate-mapping-2.2'. MSBUILD : warning : System.Xml.Schema.XmlSchemaValidationException : The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'discriminator' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'property, many-to-one, one-to-one, component, dynamic-component, any, map, set, list, bag, idbag, array, primitive-array, join, subclass, joined-subclass, union-subclass, loader, sql-insert, sql-update, sql-delete, filter' in namespace 'urn:nhibernate-mapping-2.2'. MSBUILD : warning :at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() MSBUILD : warning :at Sra.Core.Repositories.NHFluentConfigurationBuilderBase.GetConfigAndSessionFa ctory() in D:\Projects\Sra.Core\SRA.Core.Repositories\NHFluentConfigurationBuilder.cs:l ine 59 MSBUILD : warning :at Sra.Core.Repositories.NHFluentConfigurationBuilderBase.GetSession() in D:\Projects\Sra.Core\SRA.Core.Repositories\NHFluentConfigurationBuilder.cs:l ine 29 MSBUILD : warning :at Sra.Core.Entities.Repositories.Tests.BehaviourWithTransaction.StartTransacti on(Action`2 method) in D:\Projects\Sra.Core\SRA.Core.Entidades.Repositories.Tests\BehaviourWithTran saction.cs:line 14 MSBUILD : warning :at Sra.Core.Entities.Repositories.Tests.CivilParishRepositoryLoadInexistentPari shById.Should_return_null_for_non_existing_parish() in D:\Projects\Sra.Core\SRA.Core.Entidades.Repositories.Tests\CivilParishReposi toryLoadInexistentParishById.cs:line 10 MSBUILD : warning : - Inner Stack Trace - MSBUILD : warning :at FluentNHibernate.Mapping.ClassMap`1.ApplyMappings(IMappingVisitor visitor) MSBUILD : warning :at FluentNHibernate.PersistenceModel.c__DisplayClass1.ApplyMappingsb__0(ICl assMap mapping) MSBUILD : warning :at System.Collections.Generic.List`1.ForEach(Action`1 action) MSBUILD : warning :at FluentNHibernate.PersistenceModel.ApplyMappings(IMappingVisitor visitor) MSBUILD : warning :at FluentNHibernate.PersistenceModel.Configure(Configuration configuration) MSBUILD : warning :at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg) MSBUILD : warning :at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) MSBUILD : warning :at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() MSBUILD : warning : - Inner Stack Trace - I haven't changed anything in the mappins so I was wondering if anyone could help. In my previous code (where I loaded the types by hand), I made sure that abstract types shouldn't be loaded (Sra.Core.Entities.Entity is a base class reused by other entities). However, it seems like fluent is trying to map that class. Any easy way of saying that it should ignore that class? Thanks Luis
[fluent-nhib] Re: Need some explanations about LazyLoad method
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)) .SubClassIndividual((Int32) (EntityKind.Single), e = { e.Map(ind = ind.BirthDate, DataNascimento); e.ComponentBIInfo(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 ); }) .SubClassCompany((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) .SubClassIndividual(subclass = { subclass.Map(...); subclass.NotLazyLoaded(); }); However, as you can't do that currently, you can use SetAttribute instead
[fluent-nhib] Re: Need some explanations about LazyLoad method
No, I'm not talking about relationships here.just a simple class. I had a working project with a previous version of fluent. At the time, it didn't set default-lazy. When I updated to a recent release, I started getting several errors on my test complaining about not having virtual properties. It was then that I've checked the generated xml and I saw that now fluent nh sets the default-lazy attribute to true. What I don't understand is why putting the lazy=false on the class element is not enough for cancelling lazing loading on a class. The only way I solved it was to access the Conventions property of the mapping visitor and put its defaultlazyload to false. Now, this probably is not a fluent issue (though it only surfaced due to its use on my project), but I've already asked on the NH forum and nobody answered it. Thanks, From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: segunda-feira, 26 de Janeiro de 2009 18:46 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method What relationship are you talking about Luis? One-to-many? Many-to-many? Many-to-one? On Mon, Jan 26, 2009 at 6:35 PM, Luis Abreu lab...@gmail.com wrote: Guys, pause please! Ok, I can see that adding the notlazyloaded method call will put lazy = false on my class on the generated xml. Now the problem is that when this xml is loaded I get exceptions saying that my properties aren't virtual (and no, they're not and no I don't want lazy lozading on myt class). Can anyone help and tell me why NH insist in using lazy when the lazy attribute on the class is set to false and the default-lazy attribute on the nhibernate element is set to true? Thanks. -Original Message- From: fluent-nhibernate@googlegroups.com [mailto:fluent- nhibern...@googlegroups.com] On Behalf Of VisualHint Sent: segunda-feira, 26 de Janeiro de 2009 15:58 To: Fluent NHibernate Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration- 2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvid er/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name
[fluent-nhib] Re: Need some explanations about LazyLoad method
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
[fluent-nhib] Re: still about signing the assembly
Yep, I've noticed that while trying to sign them with the keys that is shipped with the code. This is a big problem because I must sign my assemblies and the latest releases of fluent NH don't allow me to do that to the framework assembly. Thanks again. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: segunda-feira, 26 de Janeiro de 2009 12:39 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: still about signing the assembly I've come across a problem with this. The FluentNHibernate.Framework project references assemblies that aren't signed themselves, which prevents us from signing it; I don't really want to sign only half of FNH! I'll see if I can remove the offending assemblies, but I don't know yet. On Fri, Jan 23, 2009 at 12:13 PM, Luis Abreu lab...@gmail.com wrote: Hello guys, I've just run na svn update on the fluent solution and it looks like it still doesn't sign the assembly and adds the APTA attribute by default. I was under the impression that this had been discussed here and fixed. Can anyone confirm it? And if that is correct, when can we get that update? Thanks, 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: Need some explanations about LazyLoad method
Btw, this is a problem I've faced in my mappings. Shouldn't the lazy attribute that you apply to a class element override that mapping? I'm asking this because I've had to change the default convention on my mappings so that I could discard the lazy loading options since it always insisted in using that when it read the xml generated by the mappers. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: segunda-feira, 26 de Janeiro de 2009 14:45 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the entity. If your methods aren't already virtual, then your lazy loading won't be working because NHibernate won't know how to track it. So what do you need to do? Update your copy of FNH and try again, failing that, explicitly set lazy loading in your class and use virtuals; that's the recommended approach. Please note, this isn't a Fluent NHibernate specific issue, you'd be seeing the same behaviour for standard xml mapping too. On Mon, Jan 26, 2009 at 8:57 AM, Paul Batum paul.ba...@gmail.com wrote: When it comes to issues such as this I am somewhat of a broken record - my suggestion is always the same: See if you can get the desired behavior using HBM xml. Once you have working xml, we can compare it to what fluent nhibernate is generating and see where the problem lies. Paul Batum On Mon, Jan 26, 2009 at 9:16 AM, Chris Marisic ch...@marisic.com wrote: I noticed this also but I assumed I was handling the session incorrectly making it fully load the object but maybe this actually is an issue. On Jan 25, 9:20 am, VisualHint cadil...@gmail.com wrote: Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no effect when called on a References() call. Nicolas On Jan 25, 3:44 am, Sebastien Lambla s...@serialseb.com wrote: But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the object is created as a proxy. Any of your property may have access or rely on other properties that need to be hydrated from the db. They all need to be virtual so that the first cal can trigger the load. This is an nhibernate thing. -- Seb _ Windows Live Messenger just got better .Video display pics, contact updates more.http://www.download.live.com/messenger --~--~-~--~~~---~--~~ 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-nhib] still about signing the assembly
Hello guys, I've just run na svn update on the fluent solution and it looks like it still doesn't sign the assembly and adds the APTA attribute by default. I was under the impression that this had been discussed here and fixed. Can anyone confirm it? And if that is correct, when can we get that update? Thanks, 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: Signing our assemblies
+1 for signing and adding the allow partial calllers attribute so that non-signed dlls can still call use the assembly. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Andrew Stewart Sent: terça-feira, 13 de Janeiro de 2009 20:09 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Signing our assemblies I think signing is a good idea, it just makes playing with other code easier, imho. Andy On Tue, Jan 13, 2009 at 7:58 PM, James Gregory jagregory@gmail.com wrote: Nobody seemed to have any opinions on it, so it's been left alone currently. The key is still distributed with the project, so you're welcome to sign it yourself until we make a decision. On Tue, Jan 13, 2009 at 7:55 PM, Ralph Balck ra...@tbalck.com wrote: I dont know if you guys have gone ahead with this or not, but im all for signing. On Dec 21 2008, 4:51 pm, James Gregory jagregory@gmail.com wrote: Guys, I'm just combing through the Issues list and one that stood out as a very easy fix concerns signing the assemblies. We already have a snk, however I thought I'd ask what everyone thought about it. Should we be signing our assemblies? I'm not really aware of the implications of signing, I realise you need it for the GAC, and you can't use unsigned assemblies from within a signed one. They all sound like good reasons to sign ours; however, are there any reasons we shouldn't be signing? James -- = I-nnovate Software - Bespoke Software Development, uk wirral. http://www.i-nnovate.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: Difficulty integrating into AutoPersistenceModel into S#arp Architecture
Hello guys. Just one thing regarding the version support and the baseclass inheritance problem: does it work when you need to customize the mappings? Remember my version + timestamp (sql server) problem? I had to give up on automapping because when I added the custom version entry for each of my entities the sql generated would always use the base class Id name instead of the derive class. Ex.: I had B which inherits form A and I wanted to generate mappings for B. And yes, I did add the c.IsBaseType entry to my conventions while defining the auto persistence model. The problem was that since I was adding a mapping entry for B so that I could set up the version to my custom type, it ended up using IdA for the sql instead of IdB. I’ve ended up using manual mappings because of this since I didn’t really had any more free time to play with it. Luis From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Andrew Stewart Sent: terça-feira, 13 de Janeiro de 2009 09:14 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Difficulty integrating into AutoPersistenceModel into S#arp Architecture Doesn't look to hard to support though, quick recap: - Pluralisation, although we don't support, I've successfully achieved this using the below: http://andrewpeters.net/inflectornet/ - Baseclass for inheritance can be set using the following convention: c.IsBaseType = b = b == typeof(BaseEntity); - Anonymous Classes, I have an patch for this here, I'll get it applied to the trunk. If I get approved on there list I'll send this accross. Andy On Tue, Jan 13, 2009 at 9:06 AM, Andrew Stewart andrew.stew...@i-nnovate.net wrote: Same here On Tue, Jan 13, 2009 at 9:03 AM, James Gregory jagregory@gmail.com wrote: Awaiting approval :) On Tue, Jan 13, 2009 at 3:52 AM, wmccaffe...@gmail.com wrote: We have been using Fluent NHibernate within S#arp Architecture and absolutely love it. A few of us have taken a stab at integrating the AutoPersistenceModel into the framework with varying success. Would someone very familiar with AutoPersistenceModel be able to lend us a hand? The discussion concerning this is at http://groups.google.com/group/sharp-architecture/browse_thread/thread/d528e 6dcb70def3a Thank you for any help or insight that you might be able to provide! Billy McCafferty -- = I-nnovate Software - Bespoke Software Development, uk wirral. http://www.i-nnovate.net -- = I-nnovate Software - Bespoke Software Development, uk wirral. http://www.i-nnovate.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Ok, that makes sense. Thanks,. --- Luis Abreu From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: sexta-feira, 9 de Janeiro de 2009 09:39 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: question on auto mapping You're missing a call to Configure. Before calling modeloPersistencia.WriteMappingsTo(@d:\); call modeloPersistencia.Configure(nhibernateConfig); On Thu, Jan 8, 2009 at 9:57 PM, Luis Abreu lab...@gmail.com wrote: Btw James, one more question: When using the auto persistence, shouldn't I be able to save the xml to disk by using the previous code? It's that I get nothing and stopping the debugger there I see 0 mappings on the persistencemodel Thanks. --- Luis Abreu From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: quinta-feira, 8 de Janeiro de 2009 16:27 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: question on auto mapping Hello Luis, I'm away from a machine with Visual Studio on right now, so I don't know how much help I can be, but lets try to work through your problem. Firstly, why is it that you're using a IUserType for your version? What is the type that your version property has in your entity? I ask that because Fluent NHibernate has a few options for mapping Versions and Timestamps. * If you call your property Timestamp and give it a type of TimeSpan, Fluent NHibernate will automatically map that to a Timestamp. * If you call your property Version, and give it a type of int or long, then it will map it as a Version. Are any of those possible options for you? On Thu, Jan 8, 2009 at 3:40 PM, Luis Abreu lab...@gmail.com wrote: Btw, one more stupid question. If I have this: var modeloPersistencia = AutoPersistenceModel.MapEntitiesFromAssemblyOfDisciplina() .Where( type = type == typeof (Disciplina) ) //comecar com disciplina .WithConvention(convention = { convention.DefaultLazyLoad = false; convention.FindIdentity = field = field.Name == Id; convention.GetTableName = type = String.Concat(type.Name, s); convention.GetVersionColumnName = type = Versao; convention.GetPrimaryKeyNameFromType = type = String.Concat(Id, type.Name); convention.IsBaseType = type = type == typeof (EntidadeBase); }); modeloPersistencia.WriteMappingsTo(@d:\); Shouldn't I get the xml mapping file for class Disciplina on d:? I've tried and I get nothing there (interestingly, if I add the modeloPersistencia.ForTypesThatDeriveFroEntidadeBase method call then I do get the xml for EntidadeBase only (which I don't want)... Thanks. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Hello again. One quick thing, it seems at the moment, the property that timestamps must be called version or timestamp, otherwise you'll have to manually map it. I tried using Timestamp but then NH tries to use datetime. That's why I'm using a custom user type and it seems like it's working (at least the PersistenceSpecification isn't throwing any errors. So, what I need is to add this from my manual mapping class: Version(d = d.Versao) .TheColumnNameIs(Versao) .SetAttributes( new Attributes { {type, ModeloOO.NH.UserTypeTimestamp,ModeloOO.NH}, {unsaved-value, null}, {generated, always} } ); So that it is applied to all the types that derive from EntidadeBase class. I tried this: var modeloPersistencia = AutoPersistenceModel.MapEntitiesFromAssemblyOfDisciplina() .Where( type = type == typeof (Disciplina) ) //comecar com disciplina .WithConvention(convention = { convention.DefaultLazyLoad = false; convention.FindIdentity = field = field.Name == Id; convention.GetTableName = type = String.Concat(type.Name, s); convention.GetVersionColumnName = type = Versao; convention.GetPrimaryKeyNameFromType = type = String.Concat(Id, type.Name); convention.IsBaseType = type = type == typeof (EntidadeBase); }); modeloPersistencia.ForTypesThatDeriveFromEntidadeBase( eb = eb.Version(d = d.Versao) .TheColumnNameIs(Versao) .SetAttributes( new Attributes { {type, ModeloOO.NH.UserTypeTimestamp,ModeloOO.NH}, {unsaved-value, null}, {generated, always} } )); But by doing this it insists on generating a class definition for Entidadebase Thanks. 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Ahh, that makes sense now my fault on the understanding. In that case your only option is to manually map the Version for each class. I see...can you give more info on how to do that? I mean, should I add classmaap derived classes with only the version definition and then merge them with my auto persistence model? If so, which methods am I supposed to use? 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Btw, one more stupid question. If I have this: var modeloPersistencia = AutoPersistenceModel.MapEntitiesFromAssemblyOfDisciplina() .Where( type = type == typeof (Disciplina) ) //comecar com disciplina .WithConvention(convention = { convention.DefaultLazyLoad = false; convention.FindIdentity = field = field.Name == Id; convention.GetTableName = type = String.Concat(type.Name, s); convention.GetVersionColumnName = type = Versao; convention.GetPrimaryKeyNameFromType = type = String.Concat(Id, type.Name); convention.IsBaseType = type = type == typeof (EntidadeBase); }); modeloPersistencia.WriteMappingsTo(@d:\); Shouldn't I get the xml mapping file for class Disciplina on d:? I've tried and I get nothing there (interestingly, if I add the modeloPersistencia.ForTypesThatDeriveFroEntidadeBase method call then I do get the xml for EntidadeBase only (which I don't want)... Thanks. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: Automapping a complex inheritance
Ok. Thanks --- Luis Abreu From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Andrew Stewart Sent: quinta-feira, 8 de Janeiro de 2009 16:04 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Automapping a complex inheritance It seems that the auto mapping of inheritance isn't clever enough to map that model yet, sorry. You'll have to manually map all descendants of Asset Sorry I hadn't spotted that sneaky one. Andy On Thu, Jan 8, 2009 at 3:29 PM, Adriano adriano.mach...@gmail.com wrote: I forgot to mention that I had already set the baseclass to my EntityBase class. On 8 jan, 12:00, Andrew Stewart andrew.stew...@i-nnovate.net wrote: Hi Luis you need to inform automapper that your base type is EntityBase rather than object, something similar to below should do the job. var autoMapper = AutoPersistenceModel .MapEntitiesFromAssemblyOfExampleClass() .Where(t = t.Namespace == FluentNHibernate.AutoMap.TestFixtures.SuperTypes) .WithConvention(c = { c.IsBaseType = b = b == typeof(EntityBase); }); Cheers Andy On Thu, Jan 8, 2009 at 1:28 PM, Adriano adriano.mach...@gmail.com wrote: Hi. I'm new to FluentNHibernate / NHibernate, and I would like to ask you guys a question about mapping complex (or deep) inheritance situations. The class hierarchy I have is the following: class Asset : EntityBase { // ... } class Fund : Asset { // ... } class EquityFund : Fund { // ... } class FixedIncomeFund : Fund { // } class Trade : EntityBase { public Asset Asset { get; set; } } I would like to use the AutoMap feature, but NHibernate keep telling me that the class Fund is being duplicated in the mappings. What am I missing? -- = I-nnovate Software - Bespoke Software Development, uk wirral.http://www.i-nnovate.net- Ocultar texto entre aspas - - Mostrar texto entre aspas - -- = I-nnovate Software - Bespoke Software Development, uk wirral. http://www.i-nnovate.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Hello James. Thanks for the help! Firstly, why is it that you're using a IUserType for your version? What is the type that your version property has in your entity? I ask that because Fluent NHibernate has a few options for mapping Versions and Timestamps. On the class, I have a Byte[] property which is mapped to a timestamp column on an sql server express database. According to the docs, the version element won't be able to match this type. that's why I had to build my own IUserVersionType. Btw, I've followed this article (though I've changed the code a little bit - removing those useless try/catch blocks were really the least I could do!): http://www.codeproject.com/KB/dotnet/OptLocking_PrefixTable.aspx Ok, now with manual mappings, I'm able to make it work (at least, I don't get any exception on my persistency checking. Now, the problem is how do I use the same version column for all the entities where all of them inherit from a base class (EntidadeBase) which is only there for the OO part... Any ideas on how to do this? 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 -~--~~~~--~~--~--~---
[fluent-nhib] Re: question on auto mapping
Btw James, one more question: When using the auto persistence, shouldn't I be able to save the xml to disk by using the previous code? It's that I get nothing and stopping the debugger there I see 0 mappings on the persistencemodel Thanks. --- Luis Abreu From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: quinta-feira, 8 de Janeiro de 2009 16:27 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: question on auto mapping Hello Luis, I'm away from a machine with Visual Studio on right now, so I don't know how much help I can be, but lets try to work through your problem. Firstly, why is it that you're using a IUserType for your version? What is the type that your version property has in your entity? I ask that because Fluent NHibernate has a few options for mapping Versions and Timestamps. * If you call your property Timestamp and give it a type of TimeSpan, Fluent NHibernate will automatically map that to a Timestamp. * If you call your property Version, and give it a type of int or long, then it will map it as a Version. Are any of those possible options for you? On Thu, Jan 8, 2009 at 3:40 PM, Luis Abreu lab...@gmail.com wrote: Btw, one more stupid question. If I have this: var modeloPersistencia = AutoPersistenceModel.MapEntitiesFromAssemblyOfDisciplina() .Where( type = type == typeof (Disciplina) ) //comecar com disciplina .WithConvention(convention = { convention.DefaultLazyLoad = false; convention.FindIdentity = field = field.Name == Id; convention.GetTableName = type = String.Concat(type.Name, s); convention.GetVersionColumnName = type = Versao; convention.GetPrimaryKeyNameFromType = type = String.Concat(Id, type.Name); convention.IsBaseType = type = type == typeof (EntidadeBase); }); modeloPersistencia.WriteMappingsTo(@d:\); Shouldn't I get the xml mapping file for class Disciplina on d:? I've tried and I get nothing there (interestingly, if I add the modeloPersistencia.ForTypesThatDeriveFroEntidadeBase method call then I do get the xml for EntidadeBase only (which I don't want)... Thanks. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---