Nie można oddać obiektu typu NHibernate.Kolekcja.Ogólne.PersistentGenericBag do listy
Mam klasę o nazwie ReportRequest jako:
public class ReportRequest
{
Int32 templateId;
List<Int32> entityIds;
public virtual Int32? Id
{
get;
set;
}
public virtual Int32 TemplateId
{
get { return templateId; }
set { templateId = value; }
}
public virtual List<Int32> EntityIds
{
get { return entityIds; }
set { entityIds = value; }
}
public ReportRequest(int templateId, List<Int32> entityIds)
{
this.TemplateId = templateId;
this.EntityIds = entityIds;
}
}
Jest mapowany za pomocą Fluent Hibernate jako:
public class ReportRequestMap : ClassMap<ReportRequest>
{
public ReportRequestMap()
{
Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
Map(x => x.TemplateId).Not.Nullable();
HasMany(x => x.EntityIds).Table("ReportEntities").KeyColumn("ReportRequestId").Element("EntityId").AsBag().Cascade.AllDeleteOrphan();
}
}
Teraz tworzę obiekt tej klasy jako
ReportRequest objReportRequest = new ReportRequest(2, new List<int>() { 11, 12, 15 });
I spróbuj zapisać obiekt w bazie danych używając
session.Save(objReportRequest);
Otrzymuję następujący błąd:
"nie można oddać obiektu typu' NHibernate. Collection.Generic. Persistentgenericbag1[System.Int32]' to type 'System.Collections.Generic.List
1[System. Int32]'."
Nie jestem pewien, czy poprawnie odwzorowałem prawa własności. Proszę. przewodnik.
Dziękuję!
80
Author: Mauricio Scheffer, 2009-10-28
1 answers
Używaj interfejsów kolekcji zamiast konkretnych kolekcji, aby NHibernate mógł wprowadzić ją z własną implementacją kolekcji.
W tym przypadku użyj IList<int>
zamiast List<int>
145
Author: Mauricio Scheffer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-28 17:16:33
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-28 17:16:33