1
Only a form that is returning me this mistake, the question that I do not know what can be or how to fix, some ask to cascade the relationship that is already.
Nhibernate.Transientobjectexception: Object References an Unsaved Transient instance - save the Transient instance before Flushing or set Cascade action for the Property to Something that would make it autosave. Type: Blogweb.Models.Vehicle, Entity: Blogweb.Models.Vehicle
Error return line:
public void Adiciona(Abastecimento abastecimento)
{
ITransaction tx = session.BeginTransaction();
session.Save(abastecimento);
tx.Commit();
}
Vehicle Mapping:
public class VeiculoMapping : ClassMap<Veiculo>
{
public VeiculoMapping()
{
Id(p => p.Id).GeneratedBy.Identity();
Map(p => p.NCarro);
Map(p => p.Modelo);
Map(p => p.Ano);
}
}
Veiculo Model:
public class Veiculo
{
public virtual int Id { get; set; }
[Required]
public virtual int NCarro { get; set; }
[Required]
public virtual string Modelo { get; set; }
public virtual int Ano { get; set; }
}
Supply Mapping:
public class AbastecimentoMapping : ClassMap <Abastecimento>
{
public AbastecimentoMapping()
{
Id(a => a.Id).GeneratedBy.Identity();
Map(a => a.DtAbastecido);
Map(a => a.Litro);
Map(a => a.VlrUnit);
Map(a => a.Km);
Map(a => a.TotalGasto);
Map(a => a.Km_Andado);
References(a => a.NomeProduto, "NomeProdutoId");
References(a => a.Autor, "AutorId");
References(a => a.NumCarro, "NumCarroId");
}
}
Abastecimento Model:
public class Abastecimento
{
public virtual int Id { get; set;}
[Required]
public virtual int Litro { get; set; }
public virtual DateTime? DtAbastecido { get; set; }
public virtual decimal VlrUnit { get; set; }
public virtual int Km { get; set; }
public virtual decimal TotalGasto { get; set; }
public virtual int Km_Andado { get; set; }
public virtual Usuario Autor { get; set; }
public virtual Compra NomeProduto { get; set; }
public virtual Veiculo NumCarro { get; set; }
}
If you formatted the PC, you brought the database beyond the project?
– EmanuelF
Yes, I brought everything including the database, I have three backups of the bank that is on the servers, on the Storage and on the computer itself
– Guilherme Padovam
@Emanuelf The rest of the form, it saves quietly, only that of the problem
– Guilherme Padovam
Refuelling is referenced the Vehicle?
– EmanuelF
@Emanuelf Supply picks up Id of the Vehicle that is on the table vehicle
– Guilherme Padovam
Just to discharge consciousness. This vehicle is already saved in the system?
– EmanuelF
@Emanuelf I discovered the error, because of a spelling error, when I put to call the class of the Vehicle, the variable is Id and I had put to call by id and not Id
– Guilherme Padovam
I was looking for something that didn’t exist, and returning the error. Solved, perfect!
– EmanuelF
@Emanuelf Don’t know the hate that I hate, I stayed 3 days with this problem and I find something stupid, but thanks for the attention and patience
– Guilherme Padovam