Technically, you can't. Not directly like that. This is a NHibernate Limitation, not a Fluent limitation.
What you need to do to get around it, is to set up a CompositeID mapping in your CountyMap, this would replace your "CountyID". The method is .UseCompositeID() on the ClassMap for CountyMap, and map your StateCode and Name as the fields for the composite key. The reason is simple. A one-to-many is the reverse side of the many-to- one. This relationship, inherently through NHibernate, will use the ID mapping of the entity containing the one-to-many when saving/looking up data from the many-to-one side. What your CountyMap is technically missing, is: HasMany(x=> x.Projects) With whatever the name of your collection is. If you don't want the collection of projects on your County class, then you can still do this, but you'll definitely need the CompositeID mapping instead of ID mapping for County. On Mar 30, 1:09 pm, Dallas <[email protected]> wrote: > Hey guys, > > I have an issue where our legacy database model isn't exactly > normalized- we have a list of Projects that need a County associated > with them. In the Counties database we have a CountyID for the > Primary Key, but in the Projects database we do not-- I need to map > the County and Location_State columns from the Projects database > against CountyName and StateAlphaCode in the Counties database. > > In ProjectMap.CS I have: > References<County>(x => x.County, "Location_State").PropertyRef(x => > x.StateCode); > > CountyMap if you need it: > public CountyMap() > { > WithTable("Counties"); > > Id(x => x.ID, "CountyID") > .WithUnsavedValue(0) > .GeneratedBy.Assigned(); > > Map(x => x.Name, "CountyName"); > Map(x => x.StateCode, "StateAlphaCode"); > } > > This is the generated SQL: > FROM Projects this_ left outer join Counties county1_ on > this_.Location_State=county1_.StateAlphaCode > > I need it to have the CountyName in there too, so this is what I need > it to generate this: > FROM Projects this_ left outer join Counties county1_ on > this_.Location_State=county1_.StateAlphaCode AND > this_.County=county1_.CountyName. > > I need a way to do 2 PropertyRef, but that fails on a Reference > already defined. So the question is, how to I map a Many to 1 against > an object where I'm NOT using its ID? > > Thank you in advance, > > -Dallas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
