Joined: Sat Aug 07, 2010 12:12 pm Posts: 2
|
I am using Fluent NHibernate to define the models and mappings. I am also fairly new to hibernate so please pardon my ignorance :)
For an object like one below: > Entity - int ID (Identity) - string Name - OtherInfo > Attribute - int ID - string Name (Unique Key) - Other info > Entity_Attribute - int ID - int EntityID (FK to Entity) - AttributeID (FK to Attribute) - Value
I have the mappings well defined and I am able add new entities, attributes and entity_attribute. But what I was wondering was if there is a way (fluent/interceptor/listener) to add an object (such as attribute or entity_attribute) if it doesn't exist in database otherwise reference the existing one.
Something which can represented by following query:
> Attribute query if exists(select id from attribute where name=@Name) begin insert attribute query select scope_Identity() end else begin select attribute's id end > Entity Attribute query if exists (select id from entity_attribute where attributeid=@attributeid and entityid=@entityid) begin insert entity_attribute query select scope_identity end else begin update entity_attribute query select id from entity_attribute end
|
|