Thanks Oskar! Creating a View is a good idea. The DB is almost a reporting DB, not a transactional one. So, INSERT/UPDATE should not be a problem.
On Jul 2, 8:19 am, Oskar Berggren <[email protected]> wrote: > Your Parent table looks exactly like a regular relation table from a > many-to-many relationship. Someone should be shot! :) > > Can you introduce a view in the database perhaps called "RealParent" > which shows the result of "SELECT DISTINCT ParentName FROM Parent"? > Then maybe you can map your Parent class to this view, and in the > mapping treat the Parent table as the relation table it is. > > Hmm... maybe this will cause problems when inserting/updating... > > Otherwise perhaps you will have to work around this in your domain > model, if no one can come up with another solution. > > /Oskar > > 2009/6/30 Sergey Shishkin <[email protected]>: > > > > > Hi, > > > I have a rather ugly legacy data model to map. > > > The entity model should look like this: > > > public class Parent > > { > > public string Name {get;set;}; > > public virtual ICollection<Child> {get;set;} > > } > > > public class Child > > { > > public string SomeProp {get;set;} > > ... > > } > > > And the legacy data model looks like this: > > > Parent > > ( > > PK ParentName nvarchar(10), > > PK FK ChildId uniqueidentifier > > ) > > > Child > > ( > > PK ChildId uniqueidentifier, > > SomeProp nvarchar(50), > > ... > > ) > > > And here is my mapping: > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > assembly="IntegrationTests, Version=1.0.0.0, Culture=neutral, > > PublicKeyToken=null" namespace="IntegrationTests.Domain"> > > <class name="Parent" table="Parent" xmlns="urn:nhibernate- > > mapping-2.2" lazy="false"> > > <id name="Name" type="String" column="Name"> > > <generator class="assigned" /> > > </id> > > </class> > > </hibernate-mapping> > > > The problem here is that when I query for Parents, I get duplicates, > > because table Parent has multiple rows per Parent entity (one per > > Child entity). I don't make composite-id because from the domain > > perspective Parent's Name distinguishes entities unambiguously. > > > Is there any way in NH to map it correctly? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
