views:

27

answers:

1

I have a class that has a many to one property defined as follows:

[NHMA.ManyToOne(Name = "TypeOfEvent", ClassType = typeof(EventType), Column="EventTypeId")]
public virtual EventType TypeOfEvent {get; set;}

Everytime I try to load the class using a simple query (just loading all of the events in the database) I get the following exception:

NHibernate.HibernateException : Creating a proxy instance failed
----> System.Reflection.AmbiguousMatchException : Ambiguous match found.

The Event table has a foreign key (EventTypeId) that relates to EventType table’s primary key EventTypeId. If I change the mapping to int everything works fine.

I realize this is probably a really simple thing, but googling around hasn’t helped. Help. Please.

A: 

I don't think you need to set the Name property on the ManyToOne attribute.

What I've used in past projects has simply been:

[ManyToOne(Column = "TypeOfEvent",
           ClassType = typeof(EventType),
           NotNull = ??)] // Set as appropriate
public virtual EventType TypeOfEvent { get; set; }

As the commenter mentioned, if you've added other namespaces to that file, the EventType class may be ambiguous; however, if it was, you should get a compiler error.

Is this a new project, or is this the first type of entity you're trying to load? Have you successfully created any other ManyToOne mappings previously in this project?

Jon Seigel