logo
down
shadow

HasOne vs References Mapping Fluent NHibernate


HasOne vs References Mapping Fluent NHibernate

By : koushikj
Date : October 15 2020, 11:12 PM
fixed the issue. Will look into that further I think you want to use the References mapping
HasOne means that the 2 entities that you are mapping together share a "mutually exclusive" identifier
code :


Share : facebook icon twitter icon
fluent-nhibernate Mapping HasOne? Reference?

fluent-nhibernate Mapping HasOne? Reference?


By : Kirby Frugia
Date : March 29 2020, 07:55 AM
I wish this help you Not sure how I should map this. I have two tables , I think you'd probably want to use:
code :
References(x => x.MatchOfTheWeek).Nullable().Column("MatchOfTheWeek");
Error: fluent NHibernate mapping which references mapping in different assembly

Error: fluent NHibernate mapping which references mapping in different assembly


By : user3145278
Date : March 29 2020, 07:55 AM
around this issue An 'unmapped class' error usually stems from the Configuration not having that ClassMap recorded.
In your FluentConfiguration, you probably have something similar to:
code :
.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T>())
.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T1>()
                .AddFromAssemblyOf<T2>())
.Diagnostics(d => d.Enable().OutputToConsole())
Fluent NHibernate mapping a Dictionary of self-references

Fluent NHibernate mapping a Dictionary of self-references


By : Sorin Stan
Date : March 29 2020, 07:55 AM
To fix this issue Can you define Answer separately and provide a mapping for it?
Something Like
code :
class Answer
{
  public virtual int Id { get; set; }
  public virtual string AnswerText { get; set; }
  public virtual Question NextQuestion { get; set; }
}
class Question
{
    public virtual int Id { get; set; }
    public virtual QuestionnaireTemplate Template { get; set; }
    public virtual string QuestionText { get; set; }
    public virtual Question PreviousQuestion { get; set; }
    private List<Answer> answers
    //Map this
    public virtual IList<Answer> AnswerList { get return answers; }
    public virtual IDictionary<string, Answer> Answers {get return answers.ToDictionary(a => a.AnswerText)}
}
Fluent nHibernate Unit Test HasOne mapping

Fluent nHibernate Unit Test HasOne mapping


By : Trevor
Date : March 29 2020, 07:55 AM
This might help you Following is what I did to implement HasOne mapping and unit test. Maps are as followed:
code :
public class PatronMap : ClassMap<Patron>
{
    public PatronMap()
    {
        Id(x => x.ID);
        Map(x => x.FirstName);
        Map(x => x.LastName);
        Map(x => x.Gender);
        Map(x => x.Age);
        Map(x => x.Address);
        Map(x => x.Occupation);
        Map(x => x.Telephone1);
        Map(x => x.Telephone2);
        Map(x => x.AshramRoom);
        HasOne(x => x.Member).ForeignKey();
        Table("Patrons");
    }
}

public class MemberMap : ClassMap<Member>
{
    public MemberMap()
    {
        Id(x => x.ID);
        Map(x => x.IsRegistered);
        Map(x => x.Reference1);
        Map(x => x.Reference2);
        References(x => x.Patron)
            .Column("PatronID")
            .Unique()
            .UniqueKey("IDX_UniquePatronID");
        Table("Members");
    }
}
public void MemberMap_Create_Success()
{
    new PersistenceSpecification<Member>( Database.Session, new CustomEqualityComparer() )
    .CheckProperty(x => x.ID, "1")
    .CheckReference(x => x.Patron, new Patron()
    {
        ID = "2",
        FirstName = "Abc",
        LastName = "Xyz",
        Gender = "M",
        Age = 99,
        Address = "Address",
        Telephone1 = 0000000001,
        Telephone2 = 1000000000,
        Occupation = "Occupation",
        AshramRoom = "Room"
    })
    .CheckProperty(x => x.Reference1, "Ref1")
    .CheckProperty(x => x.Reference2, "Ref2")
    .CheckProperty(x => x.IsRegistered, true)
    .VerifyTheMappings();
}
Fluent NHibernate HASMANY mapping without references

Fluent NHibernate HASMANY mapping without references


By : tuantai.phan
Date : March 29 2020, 07:55 AM
To fix this issue The NHibernate native way for expressing the unique reference, is:
5.1.12. one-to-one
code :
Items:     ItemID INT     ItemName VARCHAR(100)
ItemsList: ItemID INT 
public class Item
{
    public virtual int ItemId { get; set; }
    ...
    public virtual ItemMoreDetails ItemMoreDetails {get; set; }

public class ItemMoreDetails
{
    public virtual int ItemId { get; set; }
    ...
    public virtual Item Item {get; set;}
// Parent side
public class ItemMap : ClassMap<Item>
{
    public ItemMap()
    {
        Id(x => x.id).GeneratedBy.Increment();
        ...
        HasOne(x => x.ItemMoreDetails).Cascade.All();

// child side
public class ItemMoreDetailsMap: ClassMap<ItemMoreDetails>
{
    public ItemMoreDetailsMap()
    {
        ...
        References(x => x.parent).Unique();
shadow
Privacy Policy - Terms - Contact Us © bighow.org