I had to add the ActivityTypeId property to make it work. I would
rather be able to do this:
public class ActivityMappingOverride :
IAutoMappingOverride<Activity>
{
public void Override(AutoMap<Activity> mapping)
{
mapping.UseCompositeId()
.WithKeyProperty(x => x.Id)
.WithKeyProperty(x => x.ActivityType,
"ActivityType_id");
mapping.PropertiesMapped.Add(typeof(Activity).GetProperty
("Id"));
mapping.PropertiesMapped.Add(typeof(Activity).GetProperty
("ActivityType"));
}
}
... and just remove the ActivityTypeId property altogether since I
shouldn't really need it.
Jon
On Feb 12, 4:06 am, James Gregory <[email protected]> wrote:
> Hey Jon,
> Do you actually have a property called ActivityTypeId on Activity? That's a
> little odd, surely it should just be an ActivityType property. Maybe I'm
> misreading your code.
>
> You've definitely struck an unconsidered situation here, but I don't think
> it'd be too difficult to fix (I'll end up just doing the same as what you've
> done, just hidden inside the automapper).
>
> On Wed, Feb 11, 2009 at 5:32 PM, Jon Kruger <[email protected]> wrote:
>
> > OK, I solved my own problem apparently, but it's not that pretty. I
> > added an override class that looks like this:
>
> > public class ActivityMappingOverride :
> > IAutoMappingOverride<Activity>
> > {
> > public void Override(AutoMap<Activity> mapping)
> > {
> > mapping.UseCompositeId()
> > .WithKeyProperty(x => x.Id)
> > .WithKeyProperty(x => x.ActivityTypeId,
> > "ActivityType_id");
> > mapping.PropertiesMapped.Add(typeof(Activity).GetProperty
> > ("Id"));
> > mapping.PropertiesMapped.Add(typeof(Activity).GetProperty
> > ("ActivityTypeId"));
> > }
> > }
>
> > A couple things that look fishy:
>
> > 1) I had to hardcode the column name of ActivityType_id, I wish I
> > could've said .WithKeyProperty(x => x.ActivityType) and have it figure
> > out that I want to use the id from ActivityType
> > 2) I had to tell the mapping class that I already mapped the two
> > properties or it would make an Id() mapping for Id and a Map() mapping
> > for ActivityType_id when the automapper ran. The many-to-one is still
> > created though (which is good).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---