> Guid representation of that string in your model that's a separate property
That's actually the approach I am doing right now, but I have an issue with this - persitence concerns are now leaking into my domain model, which based on DDD principals. One of those principals is that the model should be entirely persistence ignorant. By having the two propeties and a mapping-of-sorts within my model, I am losing DDD purity and is something I'd like to avoid. There were two recent threads in the DDD groups regarding this, particularly around the statement that domain models shouldn't have getters and setters: - http://tech.groups.yahoo.com/group/domaindrivendesign/message/11390 - http://tech.groups.yahoo.com/group/domaindrivendesign/message/11675 Actually this topic deserves it's own thread... Thanks for your response. :) 2009/4/7 Hudson Akridge <[email protected]> > Check out 5.1.4.1 in the NHibernate > Documentation.<http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/pdf/nhibernate_reference.pdf> > That > describes what a Generator class is. Now, you can have custom generator > types that implement IIdentifierGenerator, but I don't believe this is what > you want. > In order for your ID column in the database to be created by fluent, it > reads the data type of your x.Id mapping. It will then generate the > appropriate type for your identifier. If your Id is a string type, the > appropriate column type will be used based on your NHibernate dialect choice > (which database you chose during config). > > There shouldn't be a reason to do what you're looking to do, but I've been > surprised in the past. If, for example, your Id type is a Guid in your > object model, but is stored as a string in a legacy database (nvarchar), > then you might want the functionality you're trying to get. In that case, > you could just have a string representation of the Id that is mapped, and a > Guid representation of that string in your model that's a separate property. > > If the above still doesn't make any sense to you, then it might help us out > if you gave us more information about your situation, and posted your class > data definitions. > > > On Tue, Apr 7, 2009 at 7:16 AM, Damian Hickey <[email protected]> wrote: > >> Is this achieved using Id(x => x.Id).SetGeneratorClass(string) ? >> >> >> 2009/4/6 Hudson Akridge <[email protected]> >> >> You can have a custom Generator type (versus the built in assigned and >>> generated strategies), but your entity Id needs to map directly to a >>> property on your class. That property type needs to map directly to a >>> SqlColumnType (UniqueIdentifier, Int, NVarchar, etc.). There's not really a >>> way that I'm aware of to have a custom user type for an identity column. >>> Your options are going to be limited to the basics: Int32, Int64, Guid, and >>> String (mapped to Int, BigInt, UniqueIdentifier, and NVarchar as appropriate >>> by NHibernate). >>> When you map an Id(x => x.Id), that maps directly to your Id property on >>> your mapped object (your Item class). The type of your property is inferred >>> from that expression, then given to the <id> hbm.xml element's "type" >>> attribute. Those are the basics of Id mapping with NHibernate. Check out >>> chapter 5.1.4 in the >>> NHibernateDocs.<http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/pdf/nhibernate_reference.pdf> >>> >>> I hope that helps answer your question. >>> >>> >>> On Fri, Apr 3, 2009 at 11:40 AM, Damian Hickey <[email protected]>wrote: >>> >>>> Hi, >>>> >>>> I can't set a custom type for Id, any particular reason why this is the >>>> case? >>>> >>>> Id like to write something like: >>>> >>>> public sealed class ItemMap : ClassMap<Item> { >>>> public ItemMap () { >>>> WithTable("Items"); >>>> Id(x => x.Id).*CustomTypeIs* >>>> (typeof(MyCustomUserType).GeneratedBy.Assigned(); >>>> .... >>>> } >>>> } >>>> >>>> I assume there is some fundamental reason behind this and I'm new to >>>> nhibernate.. could anyone shed any light? >>>> >>>> Thanks, >>>> >>>> Damian >>>> >>>> >>>> >>> >>> >>> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
