My bad I started stripping out the stuff not needed for the question
from the project code I am working on and got sloppy... just replace
CaseSurvey with Survey

On Oct 21, 10:34 pm, birchoff <[email protected]> wrote:
> I am new to nhibernate and I am wondering if the following is possible
> to map in fluent nhibernate or a nhibernate mapping file.
>
> For the following root entity
>
> public class Survey{
>         public long id {get;private set;}
>         public IDictionary<Question, Answer> responses {get; set;}
>
> }
>
> where the dictionary entities are defined as follows
>
> public class Question{
>         public long id {get; private set;}
>         public string text {get; set;}
>         public IList<Answer> answers {get; set;}
>
> }
>
> public class Answer{
>         public long id {get;private set;}
>         public string value {get; set;}
>
> }
>
> The NHibernate schema generation tool yields the following
>
>         create table [CaseSurvey] (
>         CaseSurvey_ID BIGINT IDENTITY NOT NULL,
>        primary key (CaseSurvey_ID)
>     )
>
>         create table [Question] (
>         Question_ID BIGINT IDENTITY NOT NULL,
>        Text NVARCHAR(255) null,
>        primary key (Question_ID)
>     )
>
>         create table [Answer] (
>         Answer_ID BIGINT IDENTITY NOT NULL,
>        Question_id BIGINT not null,
>        Value NVARCHAR(255) not null,
>        primary key (Answer_ID)
>     )
>
>         create table Responses (
>         CaseSurvey_id BIGINT not null,
>        Answer_ID BIGINT not null,
>        Question_ID BIGINT not null,
>        primary key (CaseSurvey_id, Question_ID)
>     )
>
>         alter table Responses
>         add constraint FKA95D49BF23D88E0A
>         foreign key (Answer_ID)
>         references [Answer]
>
>         alter table Responses
>         add constraint FKA95D49BFECA99CAE
>         foreign key (CaseSurvey_id)
>         references [CaseSurvey]
>
>         alter table Responses
>         add constraint FKA95D49BF585FB299
>         foreign key (Question_ID)
>         references [Question]
>
>         alter table [Answer]
>         add constraint FKCF53D3BB585FB299
>         foreign key (Question_id)
>         references [Question]
>
> From the following fluent mapping
>
>         public abstract class EntityMap<T> : ClassMap<T> where T : Entity
>     {
>         protected abstract string IdColumnName { get; }
>         protected EntityMap()
>         {
>             Id(x => x.Id, IdColumnName).GeneratedBy.Native();
>         }
>     }
>
>         public class SurveyMap : EntityMap<Survey>
>     {
>         public CaseSurveyMap()
>         {
>             HasManyToMany(x => x.Responses)
>                 .Table("Responses")
>                 .AsMap("Case_Survey_ID")
>                 .AsTernaryAssociation("Question_ID", "Answer_ID");
>         }
>
>         protected override string IdColumnName
>         {
>             get { return "CaseSurvey_ID"; }
>         }
>     }
>
>         public class QuestionMap : EntityMap<Question>
>     {
>         protected override string IdColumnName
>         {
>             get { return "Question_ID"; }
>         }
>
>         public QuestionMap()
>         {
>             Map(x => x.Text);
>                         HasMany(x => x.Answers)
>                 .KeyColumn("Question_ID")
>                 .AsBag()
>                 .Cascade.All();
>         }
>     }
>
>         public class AnswerMap : EntityMap<Answer>
>     {
>         public AnswerMap()
>         {
>             Map(x => x.Value);
>             References(x => x.Question).Not.Nullable();
>         }
>
>         protected override string IdColumnName
>         {
>             get { return "Answer_ID"; }
>         }
>     }
>
> What would I need to do to get NHibernate to merge the Answers and
> Responses table into one table.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to