Fluent NHibernate unidirectional one-to-one mapping

22 views
Skip to first unread message

Ezequiel De Luca

unread,
Sep 20, 2020, 4:59:46 AM9/20/20
to nhusers
Hi:

I am trying to create a unidirectional one-to-one relationship with fluent nhibernate as we are forced to migrate our solution from Java to C#. So far these are the Entities that I created to begin
public class RequestEntity
{
    public virtual Guid ID { get; set; }
    public virtual DateTime RequestDate { get; set; }
    public virtual string BusinessJustification { get; set; }
    public virtual UserEntity Reviewer { get; set; }
    public virtual UserEntity Approver { get; set; }
    public virtual DateTime ExpirationDate { get; set; }
}
public class UserEntity
{
    public virtual Guid Id { get; set; }
    public virtual string DisplayName { get; set; }
    public virtual string UserPrincipalName { get; set; }
}

and their respective mappings

public RequestMap()
{
    Table("tbl_requests");
    Id(x => x.ID);
    Map(x => x.RequestDate);
    Map(x => x.BusinessJustification);
    Map(x => x.ExpirationDate);
    References(x => x.Reviewer, "Reviewer").Unique();
    References(x => x.PPEDD, "PPEDD").Unique();
}
public UserMap()
{
    Table("tbl_users");
    Id(x => x.Id);
    Map(x => x.DisplayName);
    Map(x => x.UserPrincipalName);
}

I was able to perform a search on the database, but when the results are retrieved only the strId from the UserEntity is retrieved. In Java I make the following annotations:

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Reviewer", referencedColumnName = "Id")

Do you know how I can get the same in C# and fluent-nhibernate?

Danny Van den Wouwer

unread,
Sep 20, 2020, 6:08:59 AM9/20/20
to nhu...@googlegroups.com
here you have good explanations of both mapping nu code: http://notherdev.blogspot.com/2012/02/nhibernates-mapping-by-code-summary.html?m=1

Vriendelijke groeten,
Van den Wouwer Danny

Software Engineer
Peopleware NV
www.peopleware.be

Op zo 20 sep. 2020 10:59 schreef Ezequiel De Luca <delucae...@gmail.com>:
--
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 nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/9d3e7e32-9165-40a5-afea-2c3e3277dba1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages