1

I thought this would be pretty simple, but it is proving a bit more frustrating than I anticipated.

Given a structure similar to this ...

class Template { public virtual int Id { get; set; } public virtual Attached Attached { get; set; } } class Attached { public virtual int Id { get; set; } public virtual Template Template { get; set; } } 

I want the table structure to look like this.

Table - Template

Id

Table - Attached

Id - TemplateId

So I set up my mapping ...

class TemplateMap : ClassMap<Template> { TemplateMap(){ HasOne(x => x.Attached).Cascade.All(); Table("Templates"); } } class AttachedMap : ClassMap<Attached> { AttachedMap(){ References(x => x.Template).Cascade.All().Column("TemplateId"); Table("Attached"); } } 

then I create a new Template

var tmpl = new Template { Attached = new Attached { // ... } }; session.SaveOrUpdate(tmpl); transaction.Commit(); 

But my TemplateId in the Attached table still comes out Null. Any ideas?

1 Answer 1

1

I think both sides of the relationship here need to be a one to one. Also you'll need to specify on one side of the relationship that the id is generated foreignly.

Read the following 2 articles if you need more detail:
link1
link2

Edit:
Here is an example in Fluent of what I'm talking about and also what they talked about in link1:
Fluent Example

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry, those links don't really help much.
Look at the last link I just posted. This is a Fluent example so you should be able to see the general idea of what I was talking about and what they mentioned in link1
Thanks. It appears that what I want to do is just too difficult to accomplish in any simple manner. You would really think this kind of thing would be very rudimentary for nHibernate by now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.