James,
Yeah I should get round to raising some issues on this stuff at some point. But to put a marker in the sand and as a reminder to myself later. Here are a couple of things that would make dealing with conventions with edge cases like this easier: 1. A better way of checking if an IdentityPart target is an integral type. Either: a. An attribute on the Accept method b. a method/property on the IdentityPart, i.e. target.IsIdentityType 2. A better way of determining if a target is accepted by another convention. Not sure how this can be achieved without having a base class for conventions (perhaps an extension method) but it would be useful if there was a static method Accepts so that we could call !AssignedIdConvention.Accepts(target) From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: 03 June 2009 08:36 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Problems with guid primary keys and WithTable() That's a lot of steps, we should probably try to simplify that at some stage. Nice work though. On Mon, Jun 1, 2009 at 3:37 PM, Martin Hornagold <martin.hornag...@marstangroup.com> wrote: Brian, The steps to solving your problem are as follows: 1. Change your default primary key convention to only accept integral types and or ignore anything assigned by the AssignedKeyConvention: public bool Accept(IIdentityPart target) { return !(new AssignedIdConvention().Accept(target) && IsIntegralType(target.IdentityType); } private static bool IsIntegralType(Type t) { 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?); } 2. Add an AssignedKeyConvention which accepts the TblAspnetUsers entity (and any others that have assigned keys) and applies the Assigned generator to the identity: public class AssignedKeyConvention : IIdConvention { public bool Accept(IIdentityPart target) { return target.EntityType } public void Apply(IIdentityPart target) { target.GeneratedBy.Assigned(); } } 3. modify your table name convention to ignore any EntityType which breaks the convention: public bool Accept(IClassMap target) { return target.EntityType != typeof(TblAspnetUsers) } public void Apply(IClassMap target) { target.WithTable(Inflector.Net.Inflector.Pluralize(target.EntityType.Nam e)); } I think you may have fallen into the trap of many in thinking that AutoMapping overrides override the conventions. The conventions are applied afterwards. HTH ________________________________ From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Stuart Childs Sent: 01 June 2009 14:44 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Problems with guid primary keys and WithTable() Hudson is referring to the Id(...).GeneratedBy bit. Since you are using a Guid primary key, you need to call one of the following: Id(...).GeneratedBy.Guid(); // NH will call Guid.NewGuid() Id(...).GeneratedBy.GuidComb(); // Uses the Guid Comb algorithm to improve performance and indexing capabilities Id(...).GeneratedBy.Assigned(); // NH expects *you* to assign an ID before calling .Save() As for the " I get an "Identity type must be integral (int, long, uint, ulong)" error." that means that somewhere in your code you are calling Id(...).GeneratedBy.Identity(). Identity columns are integer (usually auto-incrementing) columns. As such, it makes no sense to tell NH that an integer column on the database maps to a Guid value in code. FNH helpfully throws an exception telling you that it must be integral(int, long, uint, ulong). Hope that helps. On Mon, Jun 1, 2009 at 8:14 AM, Brian Kendig <br...@enchanter.net> wrote: On May 29, 6:17 pm, Hudson Akridge <hudson.akri...@gmail.com> wrote: > I believe your generator class should be Assigned. Which generator class? I don't follow... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---