gpt4 book ai didi

c# - 流利的 Nhibernate,挣扎于一对多关系

转载 作者:太空宇宙 更新时间:2023-11-03 14:13:43 27 4
gpt4 key购买 nike

下面的异常总是被抛出:

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=?]

它的内部异常是:

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

是的!两次……

下面有代码:

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 和 Dizimo 从 Contribuicao 扩展而来。

最佳答案

请尝试在您的代码中进行以下更改:

Table("`Contribuicao`"); 

对于 Table("Contribuicao");

并在所有 Table 定义中添加它。

关于c# - 流利的 Nhibernate,挣扎于一对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7044030/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com