Off the top of my head, my guess is that it would be reasonably
straightforward to add support for use of GeneratedBy.Custom<T> to the
PrimaryKeyConvention. Have you thought about attempting this yourself?
We accept patches, and we're especially keen on getting pull requests
from users that have forked us on github :)

On Wed, Dec 16, 2009 at 12:43 AM, Beefy <[email protected]> wrote:
> THAT is why I had to override ClassMap (The class your class maps
> inherrit from). The Custom generator is NOT available in the
> PrimaryKey convention you may be trying to use... I had to have a base
> class that all of my class maps inherritted from because Custom is
> only available inside of those classes that inherit from ClassMap.
> Thus, I have on base class called CustomClassMap (above) that sits
> between my class maps and the real ClassMap class whose only job is to
> set up this custom generator for everything that inherits from it (IE
> all of my class maps).
>
> Make sense?
>
> / Michael /
>
> On Dec 13, 6:10 am, Gregory Kaidanov <[email protected]> wrote:
>> Another question ,
>> I saw that you are using
>>         Id(x => x.Id).Column
>> ("Id").GeneratedBy.Custom<MultipleHiLoPerTableGenerator>
>>
>> Custom , but in my Fluent when there is no option like this.
>> Did you create this Custom option? How can I reach it?
>>
>> On Dec 11, 4:50 pm, Beefy <[email protected]> wrote:
>>
>> > Well, what I've ended up doing for now, is overriding the ClassMap
>> > class with a custom constructor.
>>
>> >     public class CustomClassMap<T> : ClassMap<T> where T : Entity<T>
>> >     {
>> >         public CustomClassMap()
>> >         {
>> >         }
>>
>> >         public CustomClassMap(string tableName, long maxLo)
>> >         {
>> >             Id(x => x.Id).Column
>> > ("Id").GeneratedBy.Custom<MultipleHiLoPerTableGenerator>(
>> >                 p =>
>> >                 p.AddParam("table", "UniqueKeys")
>> >                  .AddParam("primary_key_column", "TableName")
>> >                  .AddParam("value_column", "NextHi")
>> >                  .AddParam("primary_key_value", tableName)
>> >                  .AddParam("max_lo", maxLo.ToString()));
>> >         }
>> >     }
>>
>> > This allows me to use it in my mapping classes like this:
>>
>> >     public class DraftingGroupMap : CustomClassMap<DraftingGroup>
>> >     {
>> >         public DraftingGroupMap()
>> >             : base ("SAAM_DraftingGroups", 1)
>> >         {
>> >             ....
>> >         }
>> >     }
>>
>> > I couldn't find a good way to get the table name automatically, so I
>> > had to find a way to pass it in (Along with the maxLo value).
>>
>> > I don't know if there was a better way to do this, but it's what I
>> > ended up doing. I'm not sure about the extension method mentioned
>> > above... I've never even seen something like that, so its hard for me
>> > to pick out whats going on exactly.
>>
>> > / Michael /
>>
>> > On Dec 11, 4:52 am, Gregory Kaidanov <[email protected]> wrote:
>>
>> > > Hello,
>> > > I am also trying to add a generator to FLuent . In my case it gets the
>> > > id fromtrigger(trigger-identity generator ) .
>> > > For now , I've inerited from GeneratorBuilder
>>
>> > >  public class FluentNHibernateExtension :
>> > > FluentNHibernate.Mapping.GeneratorBuilder
>> > >     {
>> > >         private readonly Type identityType;
>> > >         private readonly GeneratorMapping mapping;
>>
>> > >         public FluentNHibernateExtension(GeneratorMapping mapping,
>> > > Type identityType) : base (mapping,identityType)
>> > >         {
>> > >             this.mapping = mapping;
>> > >             this.identityType = identityType;
>> > >         }
>> > >         public void TriggerIdentity()
>> > >         {
>>
>> > >             EnsureIntegralIdenityType();
>> > >             SetGenerator("trigger-identity");
>>
>> > >         }
>> > >         private void EnsureIntegralIdenityType()
>> > >         {
>> > >             if (!IsIntegralType(identityType)) throw new
>> > > InvalidOperationException("Identity type must be integral (int, long,
>> > > uint, ulong)");
>> > >         }
>> > >         private static bool IsIntegralType(Type t)
>> > >         {
>> > >             // do we think we'll encounter more?
>> > >             return t == typeof(int) || t == typeof(int?)
>> > >                 || t == typeof(long) || t == typeof(long?)
>> > >                 || t == typeof(uint) || t == typeof(uint?)
>> > >                 || t == typeof(ulong) || t == typeof(ulong?)
>> > >                 || t == typeof(byte) || t == typeof(byte?)
>> > >                 || t == typeof(sbyte) || t == typeof(sbyte?)
>> > >                 || t == typeof(short) || t == typeof(short?)
>> > >                 || t == typeof(ushort) || t == typeof(ushort?);
>> > >         }
>> > >         private void SetGenerator(string generator)
>> > >         {
>> > >             mapping.Class = generator;
>> > >         }
>> > >         private void AddGeneratorParam(string name, string value)
>> > >         {
>> > >             mapping.Params.Add(name, value);
>> > >         }
>> > >     }
>>
>> > > So now , in my mapping classes I should only connect the new extension
>> > > and use it.
>> > > The problem is , I didn't find a way to connect them yet.
>> > > Any ideas?
>>
>> > > On Dec 10, 7:13 pm, Beefy <[email protected]> wrote:
>>
>> > > > Ok, so I'm being picky. I want to implement a
>> > > > MultipleHiLoPerTableGenerator class, which basically is a direct port
>> > > > of the same class from hibernate for java (I just ported the code
>> > > > over, in hopes that one day it will find it's way into NHibernate, at
>> > > > which point I should just get to change the namespace pointer for it
>> > > > and be off and running...). Heck, I'd be happy to contribute it back
>> > > > if someone would like. There's a warning about it not working with
>> > > > User supplied connections... don't know what that means though, so
>> > > > I'll continue down this path until I run painfully into another brick
>> > > > wall...
>>
>> > > > Anyway, so now I want to APPLY it to everything. I explored doing it
>> > > > in my custom PrimaryKeyConvention, but I can't find a way to (a) set a
>> > > > custom type for the generator or (b) get the table name of the current
>> > > > entity so I can pass it to the generator to use as a key. I'm assuming
>> > > > this functionality is not available (yet?)...
>>
>> > > > I could do something like this:
>>
>> > > > Id(x => x.Id).GeneratedBy.Custom<MultipleHiLoPerTableGenerator>(p =>
>> > > > p.AddParam("table", "UniqueKeys").AddParam("primary_key_value",
>> > > > "TableName"));
>>
>> > > > In each and every one of my ClassMap's, but with this whole craze over
>> > > > convention over configuration ( :-) ) I'd like to think there is a
>> > > > better way. As I said, I had an issue figuring out how to get the
>> > > > right stuff to work in the CONVENTION. Does anyone have a better
>> > > > solution?
>>
>> > > > ==
>>
>> > > > The other possibility I thought about was having all of my ClassMaps
>> > > > inherit not from ClassMap<T>, but from a CustomClassMap<T> that in
>> > > > turn inherrits from ClassMap<T>. The problem is, my abilities with
>> > > > typed classes are unfortunately limited right now, and I'm not sure
>> > > > that would even WORK. The only thing said class would do would
>> > > > basically be a ClassMap for the underlying Entity<T> class that all of
>> > > > my entities inherrit from, and would only need to define the Id line
>> > > > above. I haven't the foggiest idea how to implement that route though
>> > > > either...
>>
>> > > > Ideas please?
>
> --
>
> 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.
>
>
>

--

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.


Reply via email to