开发者

Fluent Nhibernate, Struggling With One-to-many Relationships

The follow exception is always be throwed:

could not initialize a collection: [FatorM.Sieq.Model.Entities.Culto.Ofertas#4][SQL: SELECT ofertas0_.Culto_Id as Culto3_1_, ofertas0_.Id as Id1_, ofertas0_.Id as Id9_0_, ofertas0_1_.Anonimo as Anonimo9_0_, ofertas0_1_.Banco_Id as Banco3_9_0_, ofertas0_1_.Culto_Id as Culto4_9_0_, ofertas0_1_.Frequentador_Id as Frequent5_9_0_, ofertas0_1_.NomeAvulso as NomeAvulso9_0_, ofertas0_1_.NumeroCheque as NumeroCh7_9_0_, ofertas0_1_.Valor as Valor9_0_, ofertas0_.TipoOferta_Id as TipoOferta2_11_0_ FROM dbo.[Oferta] ofertas0_ inner join dbo.[Contribuicao] ofertas0_1_ on ofertas0_.Id=ofertas0_1_.Id WHERE ofertas0_.Culto_Id=?]

It inner exception is:

Invalid column name 'Culto_Id'. Invalid column name 'Culto_Id'.

Yes! twice...

Down here has the code:

1) CultoMapping.cs:

using System;
using FluentNHibernate.Mapping;

namespace FatorM.Sieq.Model.Entities
{
    public class CultoMapping : ClassMap<Culto>
    {
        public CultoMapping()
        {
            Table("`Culto`");
            Schema("dbo");
            Id(x => x.Id)
                .GeneratedBy.Identity();
            OptimisticLock.Version();
            Not.LazyLoad();
            Map(x => x.DataCulto);
            Map(x => x.Frequentador_Id_Tesoureiro, "Frequentador_Id_Tesoureiro")
                .Not.Insert()
                .Not.Update();
            Map(x => x.Igreja_Id, "Igreja_Id")
                .Not.Insert()
                .Not.Update();
            Map(x => x.NumeroBatizados);
            Map(x => x.NumeroCulto);
            Map(x => x.NumeroPresentes);
      开发者_高级运维      Map(x => x.NumeroVisitantes);
            Map(x => x.Pastor_Id, "Pastor_Id")
                .Not.Insert()
                .Not.Update();
            Map(x => x.TotalCongregacoes);
            Map(x => x.TotalDizimos);
            Map(x => x.TotalMissoes);
            Map(x => x.TotalOfertasEspeciais);
            Map(x => x.TotalOfertasGeral);
            Map(x => x.TotalOutrasEntradas);
            HasMany(x => x.Dizimos)
                .KeyColumn("Culto_Id")
                .Inverse()
                .Cascade.All()
                .Fetch.Select().Not.LazyLoad()
                .AsBag();
            HasMany(x => x.Ofertas)
                .KeyColumn("Culto_Id")
                .Inverse()
                .Cascade.All()
                .Fetch.Select().Not.LazyLoad()
                .AsBag();
            HasManyToMany(x => x.Diaconos)
                .ChildKeyColumn("Frequentador_Id")
                .ParentKeyColumn("Culto_Id")
                .Cascade.All()
                .Table("CultoDiacono")
                .Fetch.Select().Not.LazyLoad()
                .AsBag();
            References(x => x.Tesoureiro)
                .Class(typeof(Frequentador))
                .Not.Nullable() 
                .Column("Frequentador_Id_Tesoureiro")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
            References(x => x.Igreja)
                .Class(typeof(Igreja))
                .Not.Nullable() 
                .Column("Igreja_Id")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
            References(x => x.Pastor)
                .Class(typeof(Pastor))
                .Not.Nullable() 
                .Column("Pastor_Id")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
        }
    }
}

2) OfertaMapping.cs:

    using System;
    using FluentNHibernate.Mapping;

    namespace FatorM.Sieq.Model.Entities
    {
        public class OfertaMapping : SubclassMap<Oferta>
        {
            public OfertaMapping()
            {
                Table("`Oferta`");
                Schema("dbo");
                KeyColumn("Id");
                Not.LazyLoad();
                Map(x => x.TipoOferta_Id, "TipoOferta_Id")
                    .Not.Insert()
                    .Not.Update();
                References(x => x.TipoOferta)
                    .Class(typeof(TipoOferta))
                    .Not.Nullable()
                    .Column("TipoOferta_Id")
                    .Fetch.Select().Not.LazyLoad()
                    .Cascade.All();
            }
        }
    }

3) DizimoMapping.cs:

using System;
using FluentNHibernate.Mapping;

namespace FatorM.Sieq.Model.Entities
{
    public class DizimoMapping : SubclassMap<Dizimo>
    {
        public DizimoMapping()
        {
            Table("`Dizimo`");
            Schema("dbo");
            KeyColumn("Id");
            Not.LazyLoad();
            Map(x => x.AnoReferencia);
            Map(x => x.MesReferencia);
        }
    }
}

4) ContribuicaoMapping.cs:

using System;
using FluentNHibernate.Mapping;

namespace FatorM.Sieq.Model.Entities
{
    public class ContribuicaoMapping : ClassMap<Contribuicao>
    {
        public ContribuicaoMapping()
        {
            Table("`Contribuicao`");
            Schema("dbo");
            Id(x => x.Id)
                .GeneratedBy.Identity();
            OptimisticLock.Version();
            Not.LazyLoad();
            Map(x => x.Anonimo);
            Map(x => x.Banco_Id, "Banco_Id")
                .Not.Insert()
                .Not.Update();
            Map(x => x.Culto_Id, "Culto_Id")
                .Not.Insert()
                .Not.Update();
            Map(x => x.Frequentador_Id, "Frequentador_Id")
                .Not.Insert()
                .Not.Update();
            Map(x => x.NomeAvulso);
            Map(x => x.NumeroCheque);
            Map(x => x.Valor);
            References(x => x.Banco)
                .Class(typeof(Banco))   
                .Column("Banco_Id")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
            References(x => x.Culto)
                .Class(typeof(Culto))
                .Not.Nullable() 
                .Column("Culto_Id")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
            References(x => x.Frequentador)
                .Class(typeof(Frequentador))    
                .Column("Frequentador_Id")
                .Fetch.Select().Not.LazyLoad()
                .Cascade.SaveUpdate();
        }
    }
}

Oferta and Dizimo extends from Contribuicao.


Please try in your code the following change:

Table("`Contribuicao`"); 

for Table("Contribuicao");

and make that in all Table definitions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜