Hi,
Sorry, lately I am arround here a lot, I am trying to create a ManyToOne
relationship in nhibernate and I am having a hard time trying to do it. I
am trying to link a Request with all the status that it could take during
it's life. So far I got the following
public class RequestEntity
{
public virtual Guid strID { get; set; }
...
public virtual IList<StatusChangeEntity> colStatusChange { get; set; }
}
public class StatusChangeEntity
{
public virtual Guid strCode { get; set; }
...
public virtual RequestEntity objRequest { get; set; }
}
Mapping:
public RequestMap()
{
Table("tbl_requests");
Id(x => x.strID).GeneratedBy.Guid();
...
HasMany<StatusChangeEntity>(x => x.colStatusChange)
.Cascade.All()
.KeyColumn("strRequest")
.Fetch.Join();
}
public StatusChangeMap()
{
Table("tbl_statuschanges");
Id(x => x.strCode).GeneratedBy.Guid();
References(x => x.objRequest)
.Cascade.All()
.Class<RequestEntity>()
.Column("strRequest")
.Unique();
}
It seems to work as I get the requests with it respective list of status
changes, but the list of requests contains duplicates. I got all the
request, each one of them with their list of statuschages, but each request
with more than one statuschange is return multiple times (one time per
status change).Ex:
RequestEntity1(ID=1;statuschanges(statuschange1, statuschange2)),
RequestEntity2(ID=1;statuschanges(statuschange1, statuschange2))
As a workarround when I transform the entities to BO I check the list for
duplicates before add them to the list, but I think that it should be
already cleaned when it comes from the database.
Do you know what I am skipping?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nhusers/2624504e-8a81-405f-87b1-70274dfaac58n%40googlegroups.com.