Hello guys,

I've got the following mappings:

public class OcorrenciaMapping: ClassMap<Sra.Ocorrencias.Ocorrencia> {
   HasMany(ocorrencia => ocorrencia.Intervencoes)
                    .Access.AsCamelCaseField(Prefix.Underscore)
                    .AsBag()
                    .Cascade
                    .All()
                    .KeyColumnNames.Add("IdOcorrencias")
                    .Not.LazyLoad();
}

public class IntervencaoMapping: ClassMap<Intervencao> {
         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 List<Intervencao> {intervencao};

new PersistenceSpecification<Ocorrencia>(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.

Reply via email to