c# - Nhibernate: Trouble mapping a one-to-many relationship -



c# - Nhibernate: Trouble mapping a one-to-many relationship -

i'm very, new nhibernate, , i'm there lot of obvious things i'm overlooking here, i've been searching reply few days , cannot find solution fits specific problem. really, appreciate help.

i'll describe problem first, , post code:

in object model, have "event" ilist of "organizer". want utilize nhibernate when "session.save(anevent)", info written 3 tables in database: events, organizers, , organizers_events (the bring together table). when utilize below code, next error:

invalid column name 'eventid'

my code: first, .hbm files:

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="bll" namespace="businesslogic"> <class name="event" table="events"> <id name="eventid"> <column name="id"/> <generator class="native" /> </id> <property name="name"> <column name="name"/> </property> <bag name="organizers" table="organizers_events" inverse="false" cascade="all-delete-orphan" lazy="true" access="nosetter.camelcase-underscore" > <key column="eventid"/> <one-to-many class="organizer" /> </bag> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="bll" namespace="businesslogic"> <class name="organizer" table="organizers"> <id name="id"> <column name="id"/> <generator class="native" /> </id> <property name="fullname"> <column name="fullname"/> </property> <many-to-one name="theevent" column="eventid" /> </class> </hibernate-mapping>

next, objects:

using system; using system.collections.generic; using system.linq; using system.web; /// <summary> /// summary description event /// </summary> /// namespace businesslogic { public class event { private int eventid; public virtual int eventid { { homecoming eventid; } set { eventid = value; } } private ilist<organizer> _organizers = null; public virtual ilist<organizer> organizers { { homecoming _organizers; } set { _organizers = value; } } public event() { // // todo: add together constructor logic here // } } } using system; using system.collections.generic; using system.linq; using system.text; namespace businesslogic { public class organizer:invitee { private event theevent = new event(); public virtual event theevent { { homecoming theevent; } set { theevent = value; } } } }

and finally, database schema:

create table [dbo].[events]( [id] [int] identity(1,1) not null, [name] [nvarchar](max) not null ) on [primary] create table [dbo].[organizers]( [id] [int] identity(1,1) not null, [fullname] [nvarchar](550) null ) on [primary] create table [dbo].[organizers_events]( [organizerid] [int] not null, [eventid] [int] not null ) on [primary]

i've cutting out irrelevant info simplify issue. don't think of other stuff has impact on problem here. our purposes here, want event object write it's eventid , name events table, each organizer object in ilist write id , fullname organizers table, , eventid , organizer's id written organizers_events table.

what doing wrong? if it's lot, please tell me. or if there's reply online i've missed please direct me it.

in one-to-many association don't need bring together table. bring together tables required in many-to-many assciations. right mapping

<bag name="organizers" inverse="false" cascade="all-delete-orphan" lazy="true" access="nosetter.camelcase-underscore" > <key column="eventid"/> <one-to-many class="organizer" /> </bag>

correct db schema one-to-many association

create table [dbo].[events] ( [id] [int] identity(1,1) not null, [name] [nvarchar](max) not null ) on [primary] create table [dbo].[organizers] ( [id] [int] identity(1,1) not null, [fullname] [nvarchar](550) null, [eventid] [int] not null // add together fk constraint here ) on [primary]

c# asp.net .net nhibernate nhibernate-mapping

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -