0

I'm trying to automap a class Code. Codes can have (Sub)Codes.

 public class Code
 {
    public virtual string Key{get;set;}
    public virtual Code Parent{get; set;}
    public virtual ICollection<Code> SubCodes{get;set;}
    private ICollection<Code> subCodes = new Collection<Code>();
 } 

This works but I get column IdParent and an IdCode column in my table. Naming the Parent property IdCode doesn't help then I get an IdIdCode column and the IdCode

What do I need to do to fix this.

I use Automapping with a Configuration object

k.c.
  • 1,755
  • 1
  • 29
  • 53

1 Answers1

1

Seems like your automapping uses a convention that added the prefix Id to references as well as to the Id.

If you want, You can override this convention by using your own custom ForeignKeyConvention in the AutoMap configuration.

otherwise, just name your db table columns accordingly.

Variant
  • 17,279
  • 4
  • 40
  • 65
  • The name of the column for the parent is not the problem. The point is that it is added twice: once for foreign key and once as mapping for the property. I want to expose the generated IdCode column as property to Code class, or if that is not possible have the parent field used as the column for the foreignkey by the mapping. As it stands now I have two columns in my table, and one property in my class, or one column in my table and no property in my class. By the way you are fast Variant, thanks – k.c. Jun 27 '11 at 11:08
  • Do you have a mapping convention for the `Id`? I am still not clear about what your problem is. Can you post the hbm mappings the automapping generates? |You can get them by using `ExportTo` in your Automapping configuration. – Variant Jun 27 '11 at 11:13
  • The IdCode column you get is probably the auto generated `Id` mapping. What is the Primary Key you want to use for your entity? – Variant Jun 27 '11 at 11:15
  • You are right: the problem is a foreign key convention. I inherited some of this code, and I'm not sure what all these things do :-(. So when I was working on a sample to illustrate my problem, it worked like a charm :-). Adding the convention from the code base duplicated the problem. Thanks! – k.c. Jun 28 '11 at 13:35