Derick Bailey
Derick Bailey

Reputation: 72858

Mapping an interface and concrete class with FluentNHibernate

I'm trying to map an interface and concrete class with fluentnhibernate.

here's my interface / class:


public interface IUser 
{
  int Id { get; set; }
}

public class User: IUser
{
  public int Id { get; set; }
  public string Name { get; set; }
  public string Password { get; set; }
}

here's my mapping files:


public class IUserMap: ClassMap
{
  public IUserMap()
  {
    Table("User");

    Id(u => u.Id)
      .Column("Id")
      .GeneratedBy.Native();
  }
}

public class UserMap: SubclassMap
{
  public UserMap()
  {
    Map(u => u.Name);
    Map(u => u.Password);
  }
}

and I get this error:

could not execute query
[ SELECT this_.Object_id as Id3_0_, this_.Name as Name4_0_, this_.Password as Password4_0_ FROM "User" this_ inner join User this_1_ on this_.Object_id=this_1_.Id WHERE this_.Name = @p0 ]
Positional parameters:  #0>test
[SQL: SELECT this_.Object_id as Id3_0_, this_.Name as Name4_0_, this_.Password as Password4_0_ FROM "User" this_ inner join User this_1_ on this_.Object_id=this_1_.Id WHERE this_.Name = @p0]

...

notice the "this_.Object_id" column it's looking for... that's not my ID column, but I can't specify an Id("my_id_column"); in the SubclassMap

what am I doing wrong?

Upvotes: 0

Views: 771

Answers (1)

James Gregory
James Gregory

Reputation: 14223

What kind of inheritance strategy are you trying to map with? Table-per-class or table-per-class-hierarchy? Your current mapping implies a table-per-class.

Either way, I think something's gone wrong. Object_id is the foreign key name, and it's supposed to be built by looking at the parent class's name. My guess would be that we're not treating the interface as a "parent".

Firstly, I'd recommend you raise an issue on our issues list, or maybe hit the mailing list. It'll be a bit more on our radar there.

Secondly, you could try specifying the column name explicitly, but I don't know what other repercussions there may be of the parent issue I mentioned. To specify it you should just need to do KeyColumn("Id").

Upvotes: 2

Related Questions